Пример #1
0
void UserLoginData::AppendUserFriends(MyUtil::Int2IntSeqMap& result, 
									const MyUtil::IntSeq& userFriends, 	
									const MyUtil::Int2IntSeqMap& negtiveFriendsMap) {
	MCE_INFO("[UserLoginData] AppendUserFriends");
	for (Int2IntSeqMap::iterator iter = result.begin();
			iter != result.end(); ++iter) {
		IntSeq& recommendList = iter->second;
		IntSeq tempRecommendList(recommendList);

		Int2IntSeqMap::const_iterator fIt = negtiveFriendsMap.find(iter->first);

		if (fIt != negtiveFriendsMap.end() && !recommendList.empty()) {
			for (IntSeq::const_iterator it = userFriends.begin();
					it != userFriends.end(); ++it) {
				if (find(tempRecommendList.begin(), tempRecommendList.end(), *it) != tempRecommendList.end()) {  //过滤好友中已经推出的好友
					continue;
				}

				UserLoginMapType::iterator ff = _userLoginMap.find( *it );
				if (ff == _userLoginMap.end() || (int)ff->second.count() < ACTIVEDAYS) {                  //过滤不活跃的推荐
					continue;
				}
				
				vector<int>::const_iterator userFriendIter = lower_bound(fIt->second.begin(), fIt->second.end(), *it);    //过滤好友列表
				if (userFriendIter == fIt->second.end() || *userFriendIter != *it) {
					recommendList.push_back(*it);
				}
			}
		}
	}
}
Пример #2
0
void
MyUtil::__readInt2IntSeqMap(::IceInternal::BasicStream* __is, ::MyUtil::Int2IntSeqMap& v)
{
    ::Ice::Int sz;
    __is->readSize(sz);
    while(sz--)
    {
        ::std::pair<const  ::Ice::Int, ::MyUtil::IntSeq> pair;
        __is->read(const_cast< ::Ice::Int&>(pair.first));
        ::MyUtil::Int2IntSeqMap::iterator __i = v.insert(v.end(), pair);
        __is->read(__i->second);
    }
}
Пример #3
0
void UserLoginData::AppendSingleRelationFriend(int userId, MyUtil::Int2IntSeqMap& result) {
	HotFeedSeq singleFeedList = HotFeedRecommendCacheAdapter::instance().Get(userId, -1);

	ostringstream singleFeedListStream;
	for (HotFeedSeq::iterator iter = singleFeedList.begin();
			iter != singleFeedList.end(); ++iter) {
		if (result.find(iter->userId) == result.end()) {
			result.insert(make_pair<int, IntSeq>(iter->userId, IntSeq()));
			singleFeedListStream << iter->userId << ", ";
		}
	}
	singleFeedListStream << singleFeedList.size();
	MCE_INFO("[UserLoginData] AppendSingleRelationFriend userId(" << userId << ") detail " << singleFeedListStream.str());
}
Пример #4
0
void BuddyByAddTimeLoaderAdapter::load( const MyUtil::Int2IntSeqMap& lists ){
        MCE_DEBUG( "[BuddyByAddTimeLoaderAdapter::load] lists.size()=" << lists.size() );
	try {
	        getProxy( 0 )->load( lists );
	} catch (Ice::Exception& e) {
		ostringstream info;
		for (MyUtil::Int2IntSeqMap::const_iterator ui = lists.begin(); ui != lists.end(); ++ui) {
			info << ui->first << " ";
		}
		MCE_WARN("BuddyByAddTimeLoaderAdapter::load, Ice::Exception: " << e.what() << " ids: " << info.str());
	} catch (std::exception& e) {
		MCE_WARN("BuddyByAddTimeLoaderAdapter::load,Exception: " << e.what());
	} catch (...) {
		MCE_WARN("BuddyByAddTimeLoaderAdapter::load,Exception");
	}
}
Пример #5
0
void
MyUtil::__writeInt2IntSeqMap(::IceInternal::BasicStream* __os, const ::MyUtil::Int2IntSeqMap& v)
{
    __os->writeSize(::Ice::Int(v.size()));
    ::MyUtil::Int2IntSeqMap::const_iterator p;
    for(p = v.begin(); p != v.end(); ++p)
    {
        __os->write(p->first);
        if(p->second.size() == 0)
        {
            __os->writeSize(0);
        }
        else
        {
            __os->write(&p->second[0], &p->second[0] + p->second.size());
        }
    }
}
Пример #6
0
map<int, map<int,UnivData> > UnivLinkFriends::linkFriends(map<int, map<int,UnivData> >& uds){
	map<int, map<int,UnivData> > res;
	int bTotal = 0;
	int aTotal = 0;
	for (map<int, map<int,UnivData> >::iterator itMap1 = uds.begin(); itMap1
			!= uds.end(); ++itMap1) {
		IntSeq ids;
		for ( map<int,UnivData>::iterator itMap2 = itMap1->second.begin(); itMap2 != itMap1->second.end(); ++itMap2) {
			ids.push_back( itMap2->first );
		}
		bTotal += itMap1->second.size();

		map<int,string> friends;

		MyUtil::Int2IntSeqMap buddies = xce::buddy::adapter::BuddyByAddTimeCacheAdapter::instance().getFriendLists(ids);
		for( MyUtil::Int2IntSeqMap::iterator it1=buddies.begin(); it1!=buddies.end(); ++it1 ){
			if( it1->second.size() <= 0 ){
				continue;
			}
			string& guestStr = friends[it1->first];
			for( MyUtil::IntSeq::iterator it2=it1->second.begin(); it2!=it1->second.end(); ++it2 ){
				guestStr = guestStr + "" + boost::lexical_cast<string>(*it2) + ",";
			}
		} 

		aTotal += friends.size();

		cout << "[UnivLinkFriends::linkFriends] linking mod " << itMap1->first << " size/fSize: " << itMap1->second.size() << "/" << friends.size() << endl;

		for ( map<int,string>::iterator itMap3 = friends.begin(); itMap3 != friends.end(); ++itMap3) {
			map<int,UnivData>::iterator itMap4 = itMap1->second.find( itMap3->first );
			UnivData ud = itMap4->second;
			ud.has_friends = true;
			ud.friend_list = itMap3->second;

			res[itMap1->first].insert( make_pair(itMap4->first,ud) );
		}
	}

	cout << "[UnivLinkFriends::linkFriends] size/linkedSize: " << bTotal << "/" << aTotal << endl;

	return res;
}
Пример #7
0
MyUtil::Int2IntSeqMap BuddyByAddTimeCacheAdapter::getFriendLists(const MyUtil::IntSeq& ids){
	if (ids.empty()){
		return MyUtil::Int2IntSeqMap();
	}
	size_t numCluster_sizeT = getCluster();
	int numCluster = (int)numCluster_sizeT;
	if (numCluster < 0) {
		MCE_WARN("[BuddyByAddTimeCacheAdapter::getFriendLists] this should not be seen! Why cluster=" << numCluster_sizeT << " ???" );
		return MyUtil::Int2IntSeqMap();
	}
	if (numCluster == 0 || numCluster == 1) {
		try {
			return getProxy(ids.at(0))->getFriendLists(ids);
		} catch (...) {
			return MyUtil::Int2IntSeqMap();
		}
	} else {
                vector< vector<int> > seperatedIds;
                seperatedIds.resize( numCluster );
                for( MyUtil::IntSeq::const_iterator it = ids.begin(); it
                                != ids.end(); ++it ){
                        seperatedIds.at( *it % numCluster ).push_back( *it );
                }
                MyUtil::Int2IntSeqMap result;
                for (int posCluster = 0; posCluster < numCluster; ++posCluster) {
                        MyUtil::Int2IntSeqMap someResult;
                        if( seperatedIds.at(posCluster).size() > 0 ){
                                try {
                                        someResult = getProxy(posCluster)->getFriendLists(seperatedIds.at(posCluster));
                                } catch (...) {
                                        MCE_WARN( "BuddyByAddTimeCacheAdapter::getFriendLists from Proxy(" << posCluster << ") handle unknown exception." );
                                }
                                result.insert( someResult.begin(), someResult.end() );
                        }
                }
                return result;
	}
}
Пример #8
0
void CommonFriendCalculator::buildWeight(const MyUtil::Int2IntSeqMap& users, int weight) {
	MCE_DEBUG("build " << _userId << " size=" << users.size());
	try
	{
		for(MyUtil::Int2IntSeqMap::const_iterator i=users.begin();
				i!=users.end();
				++i)
		{
			for(MyUtil::IntSeq::const_iterator ui=i->second.begin();ui!=i->second.end();++ui)
			{
				_weightCount[*ui] += weight;
				MyUtil::Int2IntSeqMap::iterator sIt = _shareCount.find(*ui);
				if(sIt == _shareCount.end())
				{
					MyUtil::IntSeq firstShares;
					firstShares.push_back( i->first );
					_shareCount.insert(make_pair(*ui, firstShares));
				}
				else
				{
					sIt->second.push_back( i->first );
				}
			}
		}
	}
	catch(Ice::Exception& e)
	{
		MCE_WARN("buildUser IceException " << _userId << e.what());
	}
	catch(std::exception& e)
	{
		MCE_WARN("buildUser stdException " << _userId << e.what());
	}
	catch(...)
	{
		MCE_WARN("buildUser exception " << _userId);
	}
}
Пример #9
0
void SetDataHelper::SetDataThread::run() {
  while (true){
    std::vector< pair<long,Ice::ObjectPtr> > to_be_set_;
    helper_.swap( to_be_set_ );
    if( to_be_set_.empty() ){
      MCE_INFO("[SetDataHelper::SetDataThread::run] setData: 0 objs." );
      continue;
    }
    ostringstream idstr;
    MyUtil::ObjectResultPtr objs = new MyUtil::ObjectResult();
    MyUtil::Int2IntSeqMap lists;
    MyUtil::Int2IntMap counts;
    for ( std::vector< pair<long, Ice::ObjectPtr> >::iterator it = to_be_set_.begin();
        it != to_be_set_.end(); ++it ){
      objs->data.insert(*it);
      MyUtil::IntSeq& list = BuddyFriendsDataPtr::dynamicCast( it->second )->friends;
      lists.insert( make_pair<Ice::Int,MyUtil::IntSeq>(it->first,list) );
      counts.insert( make_pair<Ice::Int,Ice::Int>(it->first,list.size()) );
      idstr << " " << it->first << "(" << list.size() << ")";
    }
    MCE_INFO("[SetDataHelper::SetDataThread::run] setData:" << idstr.str() );
    BuddyFriendsCacheAdapter::instance().setData(objs);
  }
}
Пример #10
0
void BuddyByNameLoaderAdapter::load( const MyUtil::Int2IntSeqMap& lists ){
	MCE_DEBUG( "[BuddyByNameLoaderAdapter::load] lists.size()=" << lists.size() );
	getProxy( 0 )->load( lists );
}
Пример #11
0
void BuddyByAddTimeLoaderI::load(const MyUtil::Int2IntSeqMap& lists,
    const Ice::Current& current) {
  MCE_INFO("[BuddyByAddTimeLoaderI::load] lists.size()=" << lists.size() );
  TaskManager::instance().execute(new LoadTask(lists));
}