Exemplo n.º 1
0
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;
    }
}
Exemplo n.º 2
0
MyUtil::IntSeq RecommendData::getFriendsRecommendRandom(int limit) {
	IceUtil::Mutex::Lock lock(*this);
	checkTimeout();	

	IntSeq result;
	Int2IntMap friendRankMap;
	for (Int2IntSeqMap::iterator iter = _recommendMap.begin();
			iter != _recommendMap.end(); ++iter) {
		if ( !iter->second.empty() ) {
			result.push_back( iter->first );

			if ( _friendrank[ iter->first ] <= 0 ) {
				friendRankMap[ iter->first ] = 1;
			} else {
				friendRankMap[ iter->first ] = _friendrank[ iter->first ];
			}
		}
	}

	if ( limit >= (int)friendRankMap.size() || limit < 0 ) {
		return result;
	}

	result.clear();

	int sum = 0;
	vector<pair<int,int> > fr;
	for (map<int,int>::const_iterator iter = friendRankMap.begin();
			iter != friendRankMap.end(); ++iter) {
		sum += iter->second;
		fr.push_back(*iter);
	}

	MCE_INFO("[RecommendData] getFriendsRecommendRandom ownerId(" << _ownerId << ") limit(" << limit << ") sum = " << sum);

	for (int i = 0; i < limit; ++i) {
		int r = 0;
		if (sum > 0) {
			r = rand() % sum;
		} else {
			MCE_WARN("[RecommendData] getFriendsRecommendRandom exception occur sum(" << sum << ")");
			break;
		}

		for (vector<pair<int,int> >::iterator iter = fr.begin();
				iter != fr.end(); ++iter) {
			r -= iter->second;
			if (r<=0) {
				result.push_back( iter->first );
				sum -= iter->second;
				iter->second = 0;
				break;
			}
		}
	}
	return result;
}
Exemplo n.º 3
0
IntSeq RoomMemberList::GetAllMembersSeq(){
  IntSeq ans;
  MemberSetIt it = _members.begin();
  for(; it != _members.end(); ++it){
    ans.push_back((*it));
  }
	MCE_DEBUG("RoomMemberList::GetAllMemberSeq --> ans.size =  "<<ans.size());
  return ans;
}
Exemplo n.º 4
0
IntSeq
IPTableManagerI::getUnivIdByIp(const string& ip, const Ice::Current& current)
{
    UnivInfoSeq seq = IPSorter::instance().get(ip);
    IntSeq res;
    for(int i =0; i<seq.size(); ++i)
    {
        res.push_back(seq.at(i)->id);
    }
    return res;
}
Exemplo n.º 5
0
MyUtil::IntSeq UserLoginData::getActiveUser(const MyUtil::IntSeq& userList) {
	MCE_INFO("[UserLoginData] getActiveUser userList size = " << userList.size());
	IntSeq result;
	for(IntSeq::const_iterator iter=userList.begin();
			iter!=userList.end(); ++iter) {
		if( _negtiveUserList.count(*iter) <= 0 ) {       //活跃用户
			result.push_back(*iter);
		}
	}	
	return result; 
}
Exemplo n.º 6
0
//--------------------------------------------------------------------------------
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);
		}
	}

}
Exemplo n.º 7
0
MyUtil::IntSeq OnlineStateFilterManagerI::getOnlineIdsFrom(const MyUtil::IntSeq& ids, const Ice::Current& current) {
    ostringstream op;
    IntSeq res;
    for( MyUtil::IntSeq::const_iterator it = ids.begin(); it != ids.end(); ++it ) {
        if( _online_state[*it] ) {
            res.push_back( *it );
            op << *it << "(" << true << ") ";
        }
    }
    MCE_INFO("OnlineStateFilterManagerI::getOnlineStateBatch -> " << op.str()
             << " " << current.con->toString().substr(current.con->toString().find("remote", 25)));
    return res;
}
Exemplo n.º 8
0
MyUtil::IntSeq StatusCacheManagerI::getStatusIdsFrom(const MyUtil::IntSeq& ids, const Ice::Current& current){
	ostringstream op;
	IntSeq res;
	for( MyUtil::IntSeq::const_iterator it = ids.begin(); it != ids.end(); ++it ){
		if( !_status[*it] ){
			res.push_back( *it );
			op << *it << "(0) ";
		}
	}
	MCE_INFO("StatusCacheManagerI::getStatusIdsFrom -> " << op.str()
                << " " << current.con->toString().substr(current.con->toString().find("remote", 25)));
	return res;
}
Exemplo n.º 9
0
MyUtil::IntSeq UserStateFilterManagerI::getGuideIdsFrom(const MyUtil::IntSeq& ids, const Ice::Current& current){
	ostringstream op;
	IntSeq res;
	for( MyUtil::IntSeq::const_iterator it = ids.begin(); it != ids.end(); ++it ){
		if( _user_state_guide[*it] ){
			res.push_back( *it );
		} else{
			op << *it << " ";
		}
	}
	MCE_INFO("UserStateFilterManagerI::getGuideIdsFrom " << ids.size() << " ids -> res: " << res.size() << " ids. filter: " << op.str()
                << " " << current.con->toString().substr(current.con->toString().find("remote", 25)));
	return res;
}
Exemplo n.º 10
0
void NoticePipe::handle(const ObjectSeq& objs){
	MessageSeq msgs;
	IntSeq ids;

	for (size_t i = 0; i < objs.size(); ++i) {
		MessagePtr m = MessagePtr::dynamicCast(objs.at(i));
		msgs.push_back(m);
		ids.push_back(m->to->userId);
	}
	JidSeqMap jmap;
	try{
		//jmap = OnlineCenterAdapter::instance().getUsersJids(ids);
		jmap = TalkFunStateAdapter::instance().getUsersJids(ids);
	}catch(Ice::Exception& e){
		//MCE_WARN("NoticePipe::handle --> call OnlineCenterAdapter.getUsersJids error : " << e);
		MCE_WARN("NoticePipe::handle --> call TalkFunStateAdapter.getUsersJids error : " << e);
	}
	MessageSeq res;
	for (size_t i = 0; i < msgs.size(); ++i) {
		JidSeqMap::iterator it = jmap.find(msgs.at(i)->to->userId);
		if (it == jmap.end()) {
			continue;
		}
		for (size_t j = 0; j < it->second.size(); ++j) {
			if (it->second.at(j)->endpoint.size() > 1
					&& it->second.at(j)->endpoint[0] == 'T') {
				MessagePtr m = new Message();
				m->from = new Jid();
				m->from->userId = -1;
				m->from->endpoint = "appnotice.talk.xiaonei.com";
				m->from->index = -1;
				m->to = it->second.at(j);
				m->type = msgs.at(i)->type;
				m->msg = msgs.at(i)->msg;

				res.push_back(m);
			}

		}
	}
	if (!res.empty()) {
		MCE_INFO("NoticePipe::handle --> Notice size:"<<res.size());
		try{
			TalkDeliverAdapter::instance().deliver(res);
		}catch(Ice::Exception& e){
			MCE_WARN("NoticePipe::handle --> call TalkDeliverAdapter.deliver error : " << e);
		}
	}
}
Exemplo n.º 11
0
MyUtil::IntSeq JourneyLogicI::getList(::Ice::Long key, ::Ice::Int limit, const Ice::Current& current) {
  using namespace xce::tripod;

  ostringstream inMsg;
  inMsg << "JourneyLogicI::getList key " << key << " limit :" << limit;
  InvokeClient ic = InvokeClient::create(current, inMsg.str(), InvokeClient::INVOKE_LEVEL_INFO);
  IntSeq result;
  StringListType resultStr;
  JourneyLogicListTripodAdapter::instance().GetSortedSet(lexical_cast<string>(key), &resultStr, 0, limit);
  for (StringListType::const_iterator iter = resultStr.begin(); iter != resultStr.end(); iter++) {
    MCE_DEBUG("JourneyLogicI::getList(::Ice::Long key) key " << key << " *iter " << *iter);
    result.push_back(lexical_cast<int>(*iter));
  }
  return result;
}
Exemplo n.º 12
0
IntSeq MemberList::getMemberList(const RoomIdPtr& rid, Affiliation affiliation) {
	//IceUtil::Mutex::Lock lock(_mutex);
	map<RoomIdPtr, map<Affiliation, set<int> > >::iterator rit =
			_members.find(rid);
	if (rit == _members.end()) {
		return IntSeq();
	}

	map<Affiliation, set<int> >::iterator it = rit->second.find(affiliation);
	if (it == rit->second.end()) {
		return IntSeq();
	}
	IntSeq seq;
	for (set<int>::iterator sit = it->second.begin(); sit != it->second.end(); ++sit) {
		seq.push_back(*sit);
	}
	return seq;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
::MyUtil::IntSeq
mop::hi::svc::model::UseredTribeSetI::getAll(::Ice::Int begin,
                         ::Ice::Int limit,
                         const Ice::Current& current)
{
	if (begin < 0) {
		begin = 0;
	}
	IceUtil::Mutex::Lock lock(*this);
	IntSeq result;
	for(IntSeq::iterator it = tribeIds.begin();
		it != tribeIds.end();
		++it)
	{
		if(begin-- > 0)	continue;
		result.push_back(*it);
		if(limit > 0 && result.size() >= limit) break;
	}
    return result;
}
Exemplo n.º 15
0
void RemoveTask::handle() {
	try {
		Statement sqlDelete;
		sqlDelete << "delete from " << TableName::recommend_friends_table(_userId)
				<< " where owner_id=" << _userId << " and friend_id=" << _friendId;
		QueryRunner("friendfinder_activeuser", CDbWServer,
			TableName::recommend_friends_table(_userId)).execute(sqlDelete);
	
		if(_block) {
			MCE_INFO("_block : true");
			Statement sqlWithBlock;
			sqlWithBlock << "insert into " << TableName::recommend_block_table(_userId)
					<< " (owner_id, friend_id, block_ids) values (" << _userId << ", "
					<< _friendId << ", " << mysqlpp::quote << IntSeqSerialize::serialize(_blockIds) << ")";
			sqlWithBlock << " on duplicate key update " << "block_ids=values(block_ids);";
			QueryRunner("friendfinder_activeuser", CDbWServer,
				TableName::recommend_block_table(_userId)).execute(sqlWithBlock);
		} else {
			MCE_INFO("_block : false");
		}

		RecommendDataPtr obj = ServiceI::instance().findObject<RecommendDataPtr>(RECOMMEND_DATA, _userId);
		if(!obj) {
			return;
		}
	
		IntSeq removeItems;
		removeItems.push_back( _friendId );
		obj->removeBatch( removeItems );
	} catch ( Ice::Exception& e ) {
		MCE_WARN("[RemoveTask] handle userId(" << _userId << ") ice exception " << e.what());
	} catch ( std::exception& e) {
		MCE_WARN("[RemoveTask] handle userId(" << _userId << ")  std exception " << e.what());
	} catch ( ... ) {
		MCE_WARN("[RemoveTask] handle userId(" << _userId << ") unknow exception");
	}
}
Exemplo n.º 16
0
MyUtil::IntSeq RecommendData::getRecommendFriendList(int friendId, int begin, int limit) {
	MCE_INFO("[RecommendData] getRecommendFriendList friendId(" << friendId << ") begin(" << begin << ") limit(" << limit << ")");
	IceUtil::Mutex::Lock lock(*this);
	checkTimeout();	
	
	Int2IntSeqMap::iterator fIt = _recommendMap.find(friendId);
	if (fIt == _recommendMap.end() || fIt->second.empty()) {
		return IntSeq();
	}

	const IntSeq& friendList = fIt->second;

	size_t realBegin = begin < 0 ? 0 : begin;
 	realBegin = realBegin < friendList.size() ? realBegin : 0;

	size_t realLimit = limit < 0 ? friendList.size() - realBegin : limit;
	realLimit = realLimit < friendList.size() - realBegin ? realLimit : friendList.size() - realBegin;
	
	MCE_DEBUG("[RecommendData] getRecommendFriendList realBegin=" << realBegin << ", realLimit=" << realLimit);

	IntSeq result;
	for (IntSeq::const_iterator iter = friendList.begin();
			iter != friendList.end(); ++iter) {
		if (realBegin > 0) {
			--realBegin;
			continue;
		}
		result.push_back(*iter);
		if (result.size() >= realLimit) {
			break;
		}
	}
	MCE_DEBUG("[RecommendData] getRecommendFriendList friendId=" << friendId << ", begin:" << begin << ", realBegin:" << 
			realBegin << ", limit:" << limit << ", realLimit:" << realLimit << "   result size=" << result.size());
	return result; 
}
Exemplo n.º 17
0
MyUtil::IntSeq RecommendData::getWriteRecommendRandom(int limit) {
    IceUtil::Mutex::Lock lock(*this);
    checkTimeout(); 

    Int2IntMap writeRecommendRank;
    for(Int2IntSeqMap::iterator iter = _recommendMap.begin();
            iter != _recommendMap.end(); ++iter) {
        if( iter->second.empty() ) {
            writeRecommendRank[ iter->first ] = _friendrank[ iter->first ];
        }
    }

    multimap<int, int> orderedRank;
    for(Int2IntMap::iterator iter = writeRecommendRank.begin(); 
            iter != writeRecommendRank.end(); ++iter) {
        orderedRank.insert( make_pair<int, int>(iter->second, iter->first) );   
    }  
       
    IntSeq writeRecommendList;
    for(multimap<int, int>::reverse_iterator iter = orderedRank.rbegin();
            iter != orderedRank.rend(); ++iter) {
        writeRecommendList.push_back( iter->second );   
    }  

	MCE_INFO("[RecommendData] getWriteRecommendRandom ownerId(" << _ownerId << ") limit(" << 
			limit << ") writeRecommendRank size(" << writeRecommendRank.size() << 
			") writeRecommendList size(" << writeRecommendList.size() << ")");
       
    if( limit >= (int)writeRecommendList.size() || limit <= 0 ) {
        return writeRecommendList;
    }

    writeRecommendList.resize( limit );

    return writeRecommendList;
}
Exemplo n.º 18
0
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;
}
Exemplo n.º 19
0
void FeedDispatcherNI::addMiniSiteFeedToGuides(long source,int type,int siteid, const MyUtil::IntSeq& guides, const Ice::Current& current) {
	static const int limit = 200;
	static const int timeval = 301;  //直接硬编码时间,如果FeedNews逻辑修改,此处需要修改
  ostringstream og;
  og<<"(";
  for(size_t i = 0; i < guides.size(); ++i) {
    og<<guides[i]<<" ";
  }
  og<<")";
	MCE_INFO("FeedDispatcherNI::addMiniSiteFeedToGuides --> source:" << source << " type:"<< type <<" siteid:"<< siteid << " guides:"<<og.str()<<" "<<current.con->toString());

  FeedConfigPtr config = new FeedConfig();
  config->sendConfig = 0;
  config->sendMiniConfig = 0;
  config->sendNewsConfig = 1;
  config->updateTime = 1;

	IntSeq siteseq;
	siteseq.push_back(siteid);
  IntSeq typeseq;
  typeseq.push_back(type);
	FeedMetaSeq items = FeedItemCacheByUseridReplicaAdapter::instance().getByTypes(siteseq, 0, limit,typeseq);

	if (items.empty()) {
		MCE_WARN("FeedDispatcherNI::addMiniSiteFeedToGuides --> FeedItemCacheByUseridReplicaAdapter::getByTypes Result is EMPTY. siteid:"<< siteid<<" type:"<<type );
		return ;
	}

	MyUtil::LongSeq feedids;
	feedids.reserve(items.size());
	for(FeedMetaSeq::iterator it = items.begin(); it != items.end(); ++it) {
		feedids.push_back(it->feedid);
	}

	ostringstream os;
	os << "( ";
	for(FeedMetaSeq::iterator it = items.begin(); it != items.end(); ++it) {
		feedids.push_back(it->feedid);
		os << it->feedid << " ";
	}
	os << ")";
	MCE_INFO("FeedDispatcherNI::addMiniSiteFeedToGuides --> Dispatcher source feedids:"<< os.str());

	FeedContentDict dict;
	try{
		dict = FeedMemcClient::instance().GetFeedDict(feedids);
	}catch(Ice::Exception& e){
		MCE_WARN("FeedDispatcherNI::addMiniSiteFeedToGuides --> err:"<<e << " file:"<<__FILE__ << " line:"<<__LINE__ << " uid:" << siteid); 
	}
	if(dict.empty()){
		MCE_WARN("FeedDispatcherNI::addMiniSiteFeedToGuides --> FeedMemcClient::GetFeedDict Result is EMPTY.");
		return ;
	}

	for(FeedMetaSeq::iterator it = items.begin(); it != items.end(); ++it) {

		FeedContentDict::iterator findit = dict.find(it->feedid);
		long feed_source = 0;
		if (findit == dict.end()) {
			ostringstream os;
      string db_instance;
    if ( isNewFeedidForDb(it->feedid)) {
         db_instance = "feed_content_db";
         if (it->feedid > 0) {
           os<< "feed_content_" << it->feedid % 100 << "_" << it->feedid/DB_CONTENT_ZONE;
         } else {
           os<< "feed_content_bc_" << abs(it->feedid)%100 << "_" << abs(it->feedid)/DB_CONTENT_ZONE;
         }
      } else {
         db_instance = "feed_db";
         os<<"feed_content_"<<it->feedid % 100;
      }
			Statement sql;
			sql << "select source from " << os.str() << " where feed = " << it->feedid;
			mysqlpp::StoreQueryResult res = QueryRunner(db_instance, CDbRServer, os.str()).store(sql);
			if (res.num_rows() <= 0) {
				MCE_INFO("FeedDispatcherNI::addMiniSiteFeedToGuides --> Not Found FeedContent. feedid:" << it->feedid);
				continue ;
			}
			mysqlpp::Row row = res.at(0);
			feed_source = row["source"];
		} else {
			feed_source = findit->second->data->source;
		}
    MCE_INFO("addMiniSiteFeedToGuides --> source:"<<source<<"  feed_source:"<<feed_source)
    if ( source != feed_source ) {
      continue;
    } else { // 满足条件,向guides们分发此新鲜事 
		  FeedSeedPtr seed = new FeedSeed;
      seed->feed = it->feedid;
      seed->actor = it->userid;
      seed->baseWeight = it->weight;
      seed->miniMerge = it->mergeid;
      seed->newsMerge = it->mergeid;
      seed->psource = 0;
      seed->ptype = 0;
      seed->source = feed_source;
      seed->time = it->time;
      seed->type = it->type;
      seed->extraProps.insert(make_pair("MachineDispatch", "addMiniSiteFeed"));  //由机器分发统一添加youjiqifenfa属性,并在Value中指定函数名

      ostringstream expr;
      for (size_t i = 0; i < guides.size() && i < 2000; ++i) {
        FeedCacheNReplicaAdapter::instance().get(guides[i]);// 推送新鲜事之前,先将guide用户加载到FeedCache中,避免出现向guide用户分发新鲜事丢失的情况
        expr << "u(" << guides[i] << ")";
        config->expr = expr.str();
        dispatch(seed, config);
        expr.str("");
        MCE_INFO("FeedDispatcherNI::addMiniSiteFeedToGuides --> dispatch feed:"<<seed->feed<<" to guide:"<<guides[i]);
      }
    }
  } 
}
Exemplo n.º 20
0
std::map<int, OfferDataNSeq> BackendProducer::createFromSameInfoFriendForHighSchool(int userId,
																																		 								int infoLimit,
																																		 								const std::map<int,int>& weights,
																																		 								const MyUtil::IntSeq& applyList,
																																		 								const MyUtil::IntSeq& friendList,
																																		 								const MyUtil::IntSeq& blockList,
																																		 								const MyUtil::IntSeq& commBlockList,
																																		 								std::ostringstream& createLog,
																																		 								std::ostringstream& createDetail)
{
	MCE_INFO("[BackendProducer] createFromSameInfoFriendForHighSchool userId:" << userId << " infoLimit:" << infoLimit);
	struct timeval tvStart, tvInfo;
	gettimeofday( &tvStart, NULL );

	map<int, OfferDataNSeq> res;
	IntSeq filterList = friendList;
	filterList.push_back(userId);
	MCE_INFO("[BackendProducer] createFromSameInfoFriendForHighSchool filterList size:" << filterList.size());

  NetworkInfo sameInfoFriends = OfferFriendsUtil::getNetworkInfoWithHostageFromDB(userId, infoLimit, filterList);

	int base_weight = 0;
	map<int, int>::const_iterator weiIt = weights.find(BaseTypeSameInfoUniv);
	if (weiIt != weights.end()) {
		base_weight = weiIt->second;
		MCE_INFO("BaseTypeSameInfoUniv: " << base_weight);
	}

	int univCount = 0;
	createDetail << " univ_";
	pair<map<int, OfferDataNSeq>::iterator, bool> ins_univ_iter = res.insert(make_pair(BaseTypeSameInfoUniv, OfferDataNSeq()));

	for (ItemSeq::iterator iter = sameInfoFriends.univInfo.begin(); 
			iter != sameInfoFriends.univInfo.end(); ++iter) {   //添加大学资料匹配好友
		for(MyUtil::IntSeq::iterator it = iter->idSeq.begin(); 
				it != iter->idSeq.end(); ++it) {
			OfferDataN infoFriend;
			infoFriend.weight = base_weight;
			infoFriend.userId = *it;
			infoFriend.sign = ((int)0) | (((int)1)<<BaseTraitSameInfoUniv);
			ins_univ_iter.first->second.push_back(infoFriend);
			createDetail << infoFriend.userId << "_";
			++univCount;
		}
	}

	base_weight = 0;
	weiIt = weights.find(BaseTypeSameInfoHighSchool);
	if (weiIt != weights.end()) {
		base_weight = weiIt->second;
	}

	int highCount = 0;
	createDetail << " high_";
	pair<map<int, OfferDataNSeq>::iterator, bool> ins_high_iter = res.insert(make_pair(BaseTypeSameInfoHighSchool, OfferDataNSeq()));

	for (ItemSeq::iterator iter = sameInfoFriends.highschoolInfo.begin(); 
			iter != sameInfoFriends.highschoolInfo.end(); ++iter) {   //添加高中资料匹配好友
		for(MyUtil::IntSeq::iterator it=iter->idSeq.begin(); it!=iter->idSeq.end(); ++it) {
			OfferDataN infoFriend;
			infoFriend.weight = base_weight;
			infoFriend.userId = *it;
			infoFriend.sign = ((int)0) | (((int)1)<<BaseTraitSameInfoHighSchool);
			ins_high_iter.first->second.push_back(infoFriend);
			createDetail << infoFriend.userId << "_";
			++highCount;
		}
	}

	base_weight = 0;
	weiIt = weights.find(BaseTypeSameInfoJuniorSchool);
	if (weiIt!=weights.end()) {
		base_weight = weiIt->second;
	}
	int juCount = 0;
	createDetail << " juni_";
	pair<map<int, OfferDataNSeq>::iterator, bool> ins_junior_iter = res.insert(make_pair(BaseTypeSameInfoJuniorSchool, OfferDataNSeq()));

	for (ItemSeq::iterator iter = sameInfoFriends.juniorschoolInfo.begin(); 
			iter != sameInfoFriends.juniorschoolInfo.end(); ++iter) {  //添加初中资料匹配好友
		for(MyUtil::IntSeq::iterator it = iter->idSeq.begin(); 
				it != iter->idSeq.end(); ++it) {
			OfferDataN infoFriend;
			infoFriend.weight = base_weight;
			infoFriend.userId = *it;
			infoFriend.sign = ((int)0) | (((int)1)<<BaseTraitSameInfoJuniorSchool);
			ins_junior_iter.first->second.push_back(infoFriend);
			createDetail << infoFriend.userId << "_";
			++juCount;
		}
	}

	base_weight = 0;
	weiIt = weights.find(BaseTypeSameInfoElementarySchool);
	if (weiIt != weights.end()) {
		base_weight = weiIt->second;
	}

	int eleCount = 0;
	createDetail << " elem_";
	pair<map<int, OfferDataNSeq>::iterator, bool> ins_ele_iter = res.insert(make_pair(BaseTypeSameInfoElementarySchool, OfferDataNSeq()));
	for (ItemSeq::iterator iter = sameInfoFriends.elementaryschoolInfo.begin(); 
			iter != sameInfoFriends.elementaryschoolInfo.end(); ++iter) {  //添加小学资料匹配好友
		for (MyUtil::IntSeq::iterator it = iter->idSeq.begin(); 
				it!=iter->idSeq.end(); ++it) {
			OfferDataN infoFriend;
			infoFriend.weight = base_weight;
			infoFriend.userId = *it;

			infoFriend.sign = ((int)0) | (((int)1)<<BaseTraitSameInfoElementarySchool);
			ins_ele_iter.first->second.push_back(infoFriend);
			createDetail << infoFriend.userId << "_";
			++eleCount;
		}
	}

	/*中学推荐*/
  HighSchoolInfo highSchoolFriends = OfferFriendsUtil::getHighSchoolInfo(userId, infoLimit, filterList);
	base_weight = 0;
	weiIt = weights.find(BaseTypeAreaEnrollSame);
	if (weiIt != weights.end()) {
		base_weight = weiIt->second;
		MCE_INFO("BaseTypeAreaEnrollSame : " << base_weight);
	}

	int areaCount = 0;
	createDetail << " area_";
	pair<map<int, OfferDataNSeq>::iterator, bool> ins_area_iter = res.insert(make_pair(BaseTypeAreaEnrollSame, OfferDataNSeq()));
	for (RecommendItemSeq::iterator iter = highSchoolFriends.highschoolseq.begin(); 
			iter != highSchoolFriends.highschoolseq.end(); ++iter) {
		OfferDataN infoFriend;
		infoFriend.weight = base_weight;
		infoFriend.userId = iter->uid;

		infoFriend.sign = ((int)0) | (((int)1)<<BaseTraitAreaEnrollSame);
		ins_area_iter.first->second.push_back(infoFriend);
		createDetail << infoFriend.userId << "_";
		++areaCount;
	}
	for (RecommendItemSeq::iterator iter = highSchoolFriends.juniorschoolseq.begin(); 
			iter != highSchoolFriends.juniorschoolseq.end(); ++iter) {
		OfferDataN infoFriend;
		infoFriend.weight = base_weight;
		infoFriend.userId = iter->uid;

		infoFriend.sign = ((int)0) | (((int)1)<<BaseTraitAreaEnrollSame);
		ins_area_iter.first->second.push_back(infoFriend);
		createDetail << infoFriend.userId << "_";
		++areaCount;
	}
	for (RecommendItemSeq::iterator iter = highSchoolFriends.collegeseq.begin(); 
			iter != highSchoolFriends.collegeseq.end(); ++iter) {
		OfferDataN infoFriend;
		infoFriend.weight = base_weight;
		infoFriend.userId = iter->uid;

		infoFriend.sign = ((int)0) | (((int)1)<<BaseTraitAreaEnrollSame);
		ins_area_iter.first->second.push_back(infoFriend);
		createDetail << infoFriend.userId << "_";
		++areaCount;
	}

	gettimeofday(&tvInfo, NULL);
	double linInfoStart = ((double)tvStart.tv_sec*1000000 + (double)tvStart.tv_usec);	
	double linInfoEnd = ((double)tvInfo.tv_sec*1000000 + (double)tvInfo.tv_usec);
	double linInfoTime = linInfoEnd - linInfoStart;
	linInfoTime = linInfoTime/1000000;
	createLog	<< " sameInfoFriends("
			<< "(u" << sameInfoFriends.univInfo.size() << ":" << univCount << ")"
			<< "(h" << sameInfoFriends.highschoolInfo.size() << ":" << highCount << ")"
			<< "(j" << sameInfoFriends.juniorschoolInfo.size() << ":" << juCount << ")"
			<< "(e" << sameInfoFriends.elementaryschoolInfo.size() << ":" << eleCount << ")"
			<< "(a" << res[BaseTypeAreaEnrollSame].size() << ":" << areaCount << ")"
			<< "(" << linInfoTime << "s)";
	MCE_INFO("BackendUtil createlog << " << createLog.str());

	return res;
}
Exemplo n.º 21
0
void FeedDispatcherNI::addMiniSiteFeed(int siteid, int userid, const Ice::Current& current ) {
	static const int limit = 5;
	static const int timeval = 301;  //直接硬编码时间,如果FeedNews逻辑修改,此处需要修改
	MCE_INFO("FeedDispatcherNI::addMiniSiteFeed siteid: " << siteid << " userid: " << userid << " limit: " << limit<<" "<<current.con->toString());

  ostringstream expr;
  expr << "u(" << userid << ")";

  FeedConfigPtr config = new FeedConfig();
  config->expr = expr.str();
  config->sendConfig = 0;
  config->sendMiniConfig = 0;
  config->sendNewsConfig = 1;
  config->updateTime = 1;

	IntSeq siteseq;
	siteseq.push_back(siteid);
	FeedMetaSeq items = FeedItemCacheByUseridReplicaAdapter::instance().get(siteseq, 0, limit);

	if (items.empty()) {
		MCE_WARN("FeedDispatcherNI::addMiniSiteFeed -> FeedItemCacheByUseridReplicaAdapter::get Result is EMPTY. siteid: " << siteid << " limit: " << limit);
		return ;
	}

	MyUtil::LongSeq feedids;
	feedids.reserve(items.size());
	for(FeedMetaSeq::iterator it = items.begin(); it != items.end(); ++it) {
		feedids.push_back(it->feedid);
	}

	ostringstream os;
	os << "[ ";
	for(FeedMetaSeq::iterator it = items.begin(); it != items.end(); ++it) {
		feedids.push_back(it->feedid);
		os << it->feedid << " ";
	}
	os << "]";
	MCE_INFO("FeedDispatcherNI::addMiniSiteFeed -> Dispatcher source feedids: " << os.str());

	FeedContentDict dict;
	try{
		dict = FeedMemcClient::instance().GetFeedDict(feedids);
	}catch(Ice::Exception& e){
		MCE_WARN("FeedDispatcherNI::addMiniSiteFeed --> err:"<<e << ", file:"<<__FILE__ << ", line:"<<__LINE__ << " uid:" << siteid); 
	}
	if(dict.empty()){
		MCE_WARN("FeedDispatcherNI::addMiniSiteFeed -> FeedMemcClient::GetFeedDict Result is EMPTY.");
		return ;
	}

	for(FeedMetaSeq::iterator it = items.begin(); it != items.end(); ++it) {

		FeedContentDict::iterator findit = dict.find(it->feedid);
		long source = 0;
		if (findit == dict.end()) {
			ostringstream os;
      string db_instance;
      if ( isNewFeedidForDb(it->feedid)) {
         db_instance = "feed_content_db";
         if (it->feedid > 0) {
           os<< "feed_content_" << it->feedid % 100 << "_" << it->feedid/DB_CONTENT_ZONE;
         } else {
           os<< "feed_content_bc_" << abs(it->feedid)%100 << "_" << abs(it->feedid)/DB_CONTENT_ZONE;
         }
      } else {
         db_instance = "feed_db";
         os<<"feed_content_"<<it->feedid % 100;
      }
			Statement sql;
			sql << "select source from " << os.str() << " where feed = " << it->feedid;
			mysqlpp::StoreQueryResult res = QueryRunner(db_instance, CDbRServer, os.str()).store(sql);
			if (res.num_rows() <= 0) {
				MCE_INFO("FeedDispatcherNI::addMiniSiteFeed Not Found FeedContent. feedid: " << it->feedid);
				continue ;
			}
			mysqlpp::Row row = res.at(0);
			source = row["source"];
		} else {
			source = findit->second->data->source;
		}

		FeedSeedPtr seed = new FeedSeed;
		seed->feed = it->feedid;
		seed->actor = it->userid;
		seed->baseWeight = it->weight;
		seed->miniMerge = it->mergeid;
		seed->newsMerge = it->mergeid;
		seed->psource = 0;
		seed->ptype = 0;
		seed->source = source;
    seed->time = it->time;
		seed->type = it->type;

		seed->extraProps.insert(make_pair("MachineDispatch", "addMiniSiteFeed"));  //由机器分发统一添加youjiqifenfa属性,并在Value中指定函数名
		dispatch(seed, config);
	} 
}