Beispiel #1
0
    def readallCheck(self, className, objid):

        recommendHelper = ClassHelper(className)
        item = recommendHelper.get(objid)
        if item:
            sid = None
            isBackupUser = False
            user = item['user']
            if item.has_key('backupUser'):
                # 感兴趣
                sid = RedisDb.hget( "recommendILatestOid", user)
                if not sid:
                    return
                isBackupUser = True
            else:
                # 相似的
                sid = RedisDb.hget( "recommendSLatestOid", user)
                if not sid:
                    return
            unreadquery = {'_sid': {"$lte": sid}, 'user': user, "read": {"$exists": False}, "backupUser": {"$exists": isBackupUser}}
            unread_count = recommendHelper.query_count( unreadquery )
            if unread_count and unread_count > 0:
                return

            import time
            if isBackupUser:
                RedisDb.zadd( 'recommendIReadAll', time.time(), user)
            else:
                RedisDb.zadd( 'recommendSReadAll', time.time(), user)
Beispiel #2
0
 def index(self):
     try:
         userid = self.user['_id']
         # userid = '5a1aea98ca714333dda69c5c'
         cursor = ClassHelper('StatCount').find({'name': {
             '$in': ['unreadMsg_' + userid, 'newFans_' + userid, 'toClaim_' + userid, 'newIncome_' + userid]}})
         unread_msg = 0
         fans = 0
         unclaimed = 0
         earnings = 0
         if cursor:
             for data in cursor:
                 if data['name'] == 'unreadMsg_' + userid:
                     unread_msg = data['count']
                 elif data['name'] == 'newFans_' + userid:
                     fans = data['count']
                 elif data['name'] == 'toClaim_' + userid:
                     unclaimed = data['count']
                 elif data['name'] == 'newIncome_' + userid:
                     earnings = data['count']
         result = {}
         result['code'] = 0
         result['errCode'] = 0
         result['fans'] = fans
         # result['unread_msg'] = unread_msg
         result['unread_msg'] = ClassHelper('Message').query_count({'to_id': userid, 'status': 0})
         result['earnings'] = earnings
         result['unclaimed'] = unclaimed
         result['feedCount'] = int(RedisDb.get('user_unread_feed_count_%s' % userid) or 0)
         faceHelper = ClassHelper( 'FaceRecommend' )
         sid = RedisDb.hget( "recommendSLatestOid", userid)
         if sid:
             query={'_sid': {"$lte": sid},'user': userid, 'read': {'$exists': False},'backupUser': {'$exists': False}}
             result['similarCount'] = faceHelper.query_count(query)
         else:
             result['similarCount'] = 0
         recommendHelper = ClassHelper('UserRecommend')
         result['possibleCount'] = recommendHelper.query_count({'user': userid})
         self.write(result)
     except Exception, e:
         logger.error(e)
         msg = traceback.format_exc()
         logger.error(msg)
         self.write(ERR_PARA.message)