void AppendSingleRelationAndSetCacheTask::handle() { IntSeq resultList; HotFeedSeq feedSeq; //try { // feedSeq = HotFeedRecommendCacheAdapter::instance().Get(_ownerId, -1); //} catch (Ice::Exception& e) { // cout << "AppendSingleRelationAndSetCacheTask HotFeedRecommendCacheAdapter Ice exception " << e.what() << endl; //} catch (std::exception& e) { // cout << "AppendSingleRelationAndSetCacheTask HotFeedRecommendCacheAdapter std exception " << e.what() << endl; //} catch (...) { // cout << "AppendSingleRelationAndSetCacheTask HotFeedRecommendCacheAdapter unknow exception" << endl; //} cout << "feedSeq size = " << feedSeq.size() << endl; for (HotFeedSeq::iterator iter = feedSeq.begin(); iter != feedSeq.end(); ++iter) { resultList.push_back(iter->userId); } //resultList.push_back(285340707); //resultList.push_back(1331); //resultList.push_back(2055206602); set<int> checkSet(resultList.begin(), resultList.end()); //cout << "AppendSingleRelationAndSetCacheTask" << endl; //for (vector<int>::iterator iter = _negtiveFriendList.begin(); // iter != _negtiveFriendList.end(); ++iter) { // cout << *iter << " "; //} //cout << endl; for (vector<int>::iterator iter = _negtiveFriendList.begin(); iter != _negtiveFriendList.end(); ++iter) { if (checkSet.find(*iter) == checkSet.end()) { resultList.push_back(*iter); } } //cout << "iijiojonojh f**k you" << endl; //for (vector<int>::iterator iter = resultList.begin(); // iter != resultList.end(); ++iter) { // cout << *iter << " "; //} //cout << endl; cout << "AppendSingleRelationAndSetCacheTask " << _ownerId << " : " << resultList.size() << endl; try { NegtiveListCacheAdapter::instance().Set(_ownerId, resultList); } catch (Ice::Exception& e) { cout << "AppendSingleRelationAndSetCacheTask NegtiveListCacheAdapter Ice exception " << e.what() << endl; } catch (std::exception& e) { cout << "AppendSingleRelationAndSetCacheTask NegtiveListCacheAdapter std exception " << e.what() << endl; } catch (...) { cout << "AppendSingleRelationAndSetCacheTask NegtiveListCacheAdapter unknow exception" << endl; } }
ObjectResultPtr UserAdsCacheManagerI::getUserAdsCacheUrlData( const IntSeq& userIds) { MyUtil::LongSeq uids; for (MyUtil::IntSeq::const_iterator it = userIds.begin(); it != userIds.end(); ++it) { uids.push_back(*it); } return ServiceI::instance().getObjectCache()->locateObjects(USER_ADS_CACHE_URL, uids); }
//-------------------------------------------------------------------------------- void VertifyPipe::handle(const ObjectSeq& seq) { //MCE_INFO("VertifyPipe::handle --> thread_id = " << pthread_self()); if (seq.empty()) { return; } else { //MCE_DEBUG("VertifyPipe::handle --> objectseq size = " <<seq.size()); } VerifySeq vSeq; IntSeq needNotVerifyUsers; for (size_t i = 0; i < seq.size(); ++i) { MessagePtr m = MessagePtr::dynamicCast(seq.at(i)); //MCE_INFO("m->from = " << m->from->userId << " m->to = " << m->to->userId); if( (m->type != MESSAGE && m->type != OFFLINE_MESSAGE) || (m->from->userId == 365734329 || m->to->userId == 365734329) ){//客服ID,不检查好友。 //MCE_INFO("VertifyPipe::handle --> m->from = " << m->from << " m->to = " << m->to); needNotVerifyUsers.push_back(i); continue; } VerifyPtr v = new Verify(); v->from = m->from->userId; v->to = m->to->userId; /*if(MESSAGE != m->type){ v->to = v->from; }*/ v->type = m->type; /* if (v->type == SYSTEM_MESSAGE) { v->sysMsgType = m->from->endpoint; }*/ v->index = i; vSeq.push_back(v); } MyUtil::IntSeq indexSeq; try{ indexSeq = TalkRightAdapter::instance().batchVerify(getIndex(), vSeq); }catch(Ice::Exception& e){ MCE_WARN("VertifyPipe::handle-->TalkRightAdapter::batchVerify-->" << e); } indexSeq.insert(indexSeq.end(), needNotVerifyUsers.begin(), needNotVerifyUsers.end()); //MCE_DEBUG("VertifyPipe::handle -->indexSeq size:"<<indexSeq.size()); for (size_t i = 0; i < indexSeq.size(); ++i) { MessagePtr m = MessagePtr::dynamicCast(seq.at(indexSeq.at(i))); //MCE_DEBUG("VertifyPipe::handle --> "<<m->to->index); if (m->to->index == 0 || m->to->index == 2 || m->to->index >1) { //MCE_DEBUG("VertifyPipe::handle --> endpoint:"<<m->to->endpoint); PipePool::instance().push(m->to->endpoint, 0, m); } } }
ObjectResultPtr UserApiCacheManagerI::getUserApiCacheData( const IntSeq& userIds) { int cluster = 4; MyUtil::LongSeq uids; for (MyUtil::IntSeq::const_iterator it = userIds.begin(); it != userIds.end(); ++it) { if ((*it)%cluster == mod_) { uids.push_back(*it); } } return retention_->locate(uids); }
::Ice::Int UserFeedsI::getItemCount(const IntSeq& userIds, const ::Ice::Current& current) { ostringstream oss; oss << " userId.size: " << userIds.size(); InvokeClient tm = InvokeClient::create(current, oss.str(), InvokeClient::INVOKE_LEVEL_INFO); int count = 0; for(IntSeq::const_iterator it = userIds.begin(); it != userIds.end(); ++it) { count += fs_.item_count(*it); } return count; }
Int2UserApiCacheDataMap UserApiCacheManagerI::getUserApiCacheList(const IntSeq& userIds, const Ice::Current&) { ObjectResultPtr objres = getUserApiCacheData(userIds); Int2UserApiCacheDataMap result; for (MyUtil::IntSeq::const_iterator it = userIds.begin(); it != userIds.end(); ++it) { ObjectMap::iterator hasRes = objres->data.find(*it); if (hasRes != objres->data.end()) { result[*it]=UserApiCacheEntryPtr::dynamicCast(hasRes->second)->GetUserApiCacheData(); } else { MCE_WARN("Not Exists: " << *it); } } return result; }
OfferDataNSeq BackendProducer::createFromIPFriend( int userId, int ipFriendLimit, const map<int,int>& weights, const IntSeq& applyList, const IntSeq& friendList, const IntSeq& blockList, const IntSeq& commBlockList, ostringstream& createLog, ostringstream& createDetail ){ struct timeval tvStart, tvIP; gettimeofday( &tvStart, NULL ); OfferDataNSeq res; IntSeq filterList( friendList ); filterList.push_back(userId); filterList.insert( filterList.end(), applyList.begin(), applyList.end() ); sort( filterList.begin(), filterList.end() ); int ipLimit = 1; xce::friendfinder::IPNoteSeq ipSeq = OfferFriendsUtil::getFreqIP(userId, ipLimit); int base_weight = 0; map<int,int>::const_iterator weiIt = weights.find(BaseTypeIPSame); if( weiIt!=weights.end() ) base_weight = weiIt->second; vector<int> ipFriends; createDetail << " ip_"; if( !ipSeq.empty() ) { ipFriends = OfferFriendsUtil::getUsersWithMaskByIP( ipSeq.at(0).ip, ipFriendLimit, filterList ); /* char chrLongValue[30]; sprintf(chrLongValue, "%lu", ipSeq.at(0).ip); */ for(vector<int>::iterator iter=ipFriends.begin(); iter!=ipFriends.end(); ++iter){ OfferDataN ipFriend; ipFriend.userId = *iter; ipFriend.weight = base_weight; //ipFriend.infos.insert(pair<int, string>(BaseTraitIPSame, string(chrLongValue))); ipFriend.sign = ((int)0) | (((int)1)<<BaseTraitIPSame); res.push_back(ipFriend); createDetail << ipFriend.userId << "_"; } createLog << " ipFriends(" << ipSeq.at(0).ip << ")(" << ipFriends.size() << ")"; } else { createLog << " ipFriends(0)(" << ipFriends.size() << ")"; } gettimeofday( &tvIP, NULL ); double linIPStart = ((double)tvStart.tv_sec*1000000 + (double)tvStart.tv_usec); double linIPEnd = ((double)tvIP.tv_sec*1000000 + (double)tvIP.tv_usec); double linIPTime = linIPEnd - linIPStart; linIPTime = linIPTime/1000000; createLog << "(" << linIPTime << "s)"; return res; }
ObjectResultPtr UserAdsCacheManagerI::getUserAdsCacheData( const IntSeq& userIds) { MyUtil::LongSeq uids; for (MyUtil::IntSeq::const_iterator it = userIds.begin(); it != userIds.end(); ++it) { uids.push_back(*it); } ObjectResultPtr result = new ObjectResult; ObjectResultPtr obj = ServiceI::instance().getObjectCache()->locateObjects(USER_ADS_CACHE_URL, uids); for(MyUtil::ObjectMap::const_iterator it = obj->data.begin(); it != obj->data.end(); ++it) { result->data.insert(make_pair((*it).first, toOld(UserAdsCacheUrlDataPtr::dynamicCast((*it).second)))); } // return ServiceI::instance().getObjectCache()->locateObjects(USER_ADS_CACHE_URL, uids); return result; }
Int2UserAdsCacheDataMap UserAdsCacheManagerI::getUserAdsCacheList(const IntSeq& userIds, const Ice::Current& current) { ostringstream msg; msg << "UserAdsCacheManagerI::getUserAdsCacheList -> size: " << userIds.size() << " " << current.con->toString().substr(current.con->toString().find("remote",25)); TimeCost tc = TimeCost::create(msg.str()); ObjectResultPtr objres = getUserAdsCacheData(userIds); Int2UserAdsCacheDataMap result; for (MyUtil::IntSeq::const_iterator it = userIds.begin(); it != userIds.end(); ++it) { ObjectMap::iterator hasRes = objres->data.find(*it); if (hasRes != objres->data.end()) { result[*it]=toOld(UserAdsCacheUrlDataPtr::dynamicCast(hasRes->second)); } else { MCE_WARN("Not Exists: " << *it); } } return result; }
long TicketAdapter::verifyTicket(const string& ticket, const IntSeq& types) { long result = -1; if(TicketUtil::isSTicketLegal(ticket)) { KeySeq keys, missedKeys; keys.push_back(ticket); DataMap dataMap = _tripodClient->get(keys, missedKeys); DataMap::const_iterator itm = dataMap.find(ticket); if(itm != dataMap.end()) { TicketData data; string value(itm->second.begin(), itm->second.end()); istringstream in(value); data.ParseFromIstream(&in); int type = data.type(); for(IntSeq::const_iterator it = types.begin(); it != types.end(); ++it) { if(type == *it) { result = data.id(); break; } } } } return result; }
MyUtil::Int2IntSeqMap UserLoginData::getRecommendFriends(int userId) { IceUtil::RWRecMutex::RLock lock(_init_flag_mutex); MCE_INFO("[UserLoginData] getRecommendFriends userId(" << userId << ") _userLoginMap size(" << _userLoginMap.size() << ") ACTIVEDAYS(" << ACTIVEDAYS << ")"); struct timeval tvStart,tvEnd; double linStart = 0, linEnd = 0, lTime = 0; gettimeofday( &tvStart, NULL ); Int2IntSeqMap result; UserLoginMapType::iterator fIt = _userLoginMap.find(userId); if( fIt == _userLoginMap.end() || (int)fIt->second.count() < ACTIVEDAYS ) { //不是活跃用户 return result; } vector<int> friendList; try { friendList = BuddyByIdCacheAdapter::instance().getFriendListAsc(userId, -1); } catch ( Ice::Exception& e ) { MCE_WARN(time(NULL) << "[UserLoginData] getRecommendFriends BuddyByIdCacheAdapter Ice Exception : " << e.what() << "\n"); } catch ( ... ) { MCE_WARN(time(NULL) << "[UserLoginData] getRecommendFriends BuddyByIdCacheAdapter Unknow Exception"); } MCE_DEBUG("[UserLoginData] getRecommendFriends friendList size(" << friendList.size() << ")"); vector<int> negtiveFriendsList; for (vector<int>::iterator iter = friendList.begin(); iter != friendList.end(); ++iter) { if( _negtiveUserList.count(*iter) > 0 ) { negtiveFriendsList.push_back( *iter ); //找出不活跃的好友 } } if( negtiveFriendsList.empty() ) { return result; } Int2IntSeqMap friendsMap; try { friendsMap = BuddyByIdCacheAdapter::instance().getFriendLists( negtiveFriendsList ); } catch ( Ice::Exception& e ) { MCE_WARN(time(NULL) << "[UserLoginData] getRecommendFriends BuddyByIdCacheAdapter Ice Exception : " << e.what() << "\n"); } catch ( ... ) { MCE_WARN(time(NULL) << "[UserLoginData] getRecommendFriends BuddyByIdCacheAdapter Unknow Exception"); } MCE_DEBUG("[UserLoginData] getRecommendFriends negtiveFriendsList size(" << negtiveFriendsList.size() << ") friendsMap size(" << friendsMap.size() << ")"); vector<int> recommendFriend; ostringstream idPair; for (Int2IntSeqMap::iterator iter = friendsMap.begin(); iter != friendsMap.end(); ++iter) { recommendFriend = FriendFinderInfoCacheReplicaAdapter::instance().getGuestInfoMatchFriendList(userId, iter->first, -1); result[iter->first] = vector<int>(); idPair << "(" << iter->first << "," << recommendFriend.size() << ") "; for (vector<int>::iterator it = recommendFriend.begin(); it != recommendFriend.end(); ++it) { UserLoginMapType::iterator ff = _userLoginMap.find( *it ); if (ff == _userLoginMap.end() || (int)ff->second.count() < ACTIVEDAYS) { //过滤不活跃的推荐 continue; } vector<int>::iterator fIt = lower_bound( iter->second.begin(), iter->second.end(), *it ); //过滤好友列表 if (fIt == iter->second.end() || *fIt != *it) { result[iter->first].push_back( *it ); } } recommendFriend.clear(); } //AppendSingleRelationFriend(userId, result); //添加单向好友 Int2IntSeqMap blockFriends; IntSeq tmpVec; RelationBatchHelper::getBlockResult( userId, blockFriends); MCE_DEBUG("[UserLoginData] getRecommendFriends recommend Friends " << idPair.str() << " blockFriends size=" << blockFriends.size()); IntSeq recf; for (Int2IntSeqMap::iterator iter = blockFriends.begin(); //过滤block列表 iter != blockFriends.end(); ++iter) { recf = result[iter->first]; for (IntSeq::iterator it = recf.begin(); it != recf.end(); ++it) { if( find(iter->second.begin(), iter->second.end(), *it) == iter->second.end() ) { tmpVec.push_back( *it ); } } if( tmpVec.empty() ) { //如果没有可以推荐的人则不再出现该用户 result.erase( iter->first ); } else { result[iter->first] = tmpVec; } tmpVec.clear(); recf.clear(); } ostringstream idEmptySize; ostringstream idSize; for (Int2IntSeqMap::iterator iter = result.begin(); iter != result.end(); ++iter) { if (iter->second.empty()) { idEmptySize << iter->first << ", "; } else { idSize << "(" << iter->first << "," << iter->second.size() << ") "; } } //AppendUserFriends(result, friendList, friendsMap); for (Int2IntSeqMap::iterator iter=result.begin(); iter!=result.end(); ++iter) { //精简内存 IntSeq( iter->second ).swap( iter->second ); } gettimeofday( &tvEnd, NULL ); linStart = ((double)tvStart.tv_sec*1000000 + (double)tvStart.tv_usec); linEnd = ((double)tvEnd.tv_sec*1000000 + (double)tvEnd.tv_usec); lTime = linEnd - linStart; lTime = lTime/1000000; MCE_DEBUG("write :: " << idEmptySize.str() << " friend :: " << idSize.str() << " result size=" << result.size() << " cost time=" << lTime << "second!"); return result; }