Merge pull request #1377 from G10h4ck/jsonapi

GXS deep search notify results also of already known groups
This commit is contained in:
csoler 2018-10-20 14:47:37 +02:00 committed by GitHub
commit cfe95a57a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 32 deletions

View File

@ -1373,7 +1373,7 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
RsStackMutex stack(mDbMutex); RS_STACK_MUTEX(mDbMutex);
#ifdef RS_DATA_SERVICE_DEBUG_TIME #ifdef RS_DATA_SERVICE_DEBUG_TIME
rstime::RsScopeTimer timer(""); rstime::RsScopeTimer timer("");

View File

@ -1659,12 +1659,13 @@ void RsGenExchange::receiveNewMessages(std::vector<RsNxsMsg *>& messages)
void RsGenExchange::receiveDistantSearchResults(TurtleRequestId id,const RsGxsGroupId &grpId) void RsGenExchange::receiveDistantSearchResults(TurtleRequestId id,const RsGxsGroupId &grpId)
{ {
std::cerr << __PRETTY_FUNCTION__ << " received result for request "
<< std::hex << id << std::dec << std::endl;
RS_STACK_MUTEX(mGenMtx); RS_STACK_MUTEX(mGenMtx);
RsGxsDistantSearchResultChange* gc = new RsGxsDistantSearchResultChange(id,grpId); RsGxsDistantSearchResultChange* gc = new RsGxsDistantSearchResultChange(id,grpId);
mNotifications.push_back(gc); mNotifications.push_back(gc);
std::cerr << "RsGenExchange::receiveDistantSearchResults(): received result for request " << std::hex << id << std::dec << std::endl;
} }
void RsGenExchange::notifyReceivePublishKey(const RsGxsGroupId &grpId) void RsGenExchange::notifyReceivePublishKey(const RsGxsGroupId &grpId)

View File

@ -5181,7 +5181,9 @@ bool RsGxsNetService::clearDistantSearchResults(const TurtleRequestId& id)
mDistantSearchResults.erase(id); mDistantSearchResults.erase(id);
return true ; return true ;
} }
void RsGxsNetService::receiveTurtleSearchResults(TurtleRequestId req, const std::list<RsGxsGroupSummary>& group_infos)
void RsGxsNetService::receiveTurtleSearchResults(
TurtleRequestId req, const std::list<RsGxsGroupSummary>& group_infos )
{ {
std::set<RsGxsGroupId> groupsToNotifyResults; std::set<RsGxsGroupId> groupsToNotifyResults;
@ -5192,36 +5194,40 @@ void RsGxsNetService::receiveTurtleSearchResults(TurtleRequestId req, const std:
std::map<RsGxsGroupId,RsGxsGroupSummary>& std::map<RsGxsGroupId,RsGxsGroupSummary>&
search_results_map(mDistantSearchResults[req]); search_results_map(mDistantSearchResults[req]);
for(auto it(group_infos.begin());it!=group_infos.end();++it) for(const RsGxsGroupSummary& gps : group_infos)
if(search_results_map.find((*it).mGroupId) == search_results_map.end()) if(search_results_map.find(gps.mGroupId) == search_results_map.end())
grpMeta[(*it).mGroupId] = NULL; grpMeta[gps.mGroupId] = nullptr;
mDataStore->retrieveGxsGrpMetaData(grpMeta); mDataStore->retrieveGxsGrpMetaData(grpMeta);
// only keep groups that are not locally known, and groups that are not already in the mDistantSearchResults structure for (const RsGxsGroupSummary& gps : group_infos)
for(auto it(group_infos.begin());it!=group_infos.end();++it)
if(grpMeta[(*it).mGroupId] == NULL)
{ {
const RsGxsGroupId& grpId((*it).mGroupId); #ifndef RS_DEEP_SEARCH
/* Only keep groups that are not locally known, and groups that are
* not already in the mDistantSearchResults structure. */
if(grpMeta[gps.mGroupId]) continue;
#else // ndef RS_DEEP_SEARCH
/* When deep search is enabled search results may bring more info
* then we already have also about post that are indexed by xapian,
* so we don't apply this filter in this case. */
#endif
const RsGxsGroupId& grpId(gps.mGroupId);
groupsToNotifyResults.insert(grpId); groupsToNotifyResults.insert(grpId);
auto it2 = search_results_map.find(grpId); auto it2 = search_results_map.find(grpId);
if(it2 != search_results_map.end()) if(it2 != search_results_map.end())
{ {
// update existing data // update existing data
RsGxsGroupSummary& eGpS(it2->second);
it2->second.mPopularity++; eGpS.mPopularity++;
it2->second.mNumberOfMessages = std::max( eGpS.mNumberOfMessages = std::max(
it2->second.mNumberOfMessages, eGpS.mNumberOfMessages,
(*it).mNumberOfMessages ); gps.mNumberOfMessages );
} }
else else
{ {
search_results_map[grpId] = *it; search_results_map[grpId] = gps;
search_results_map[grpId].mPopularity = 1; // number of results so far // number of results so far
search_results_map[grpId].mPopularity = 1;
} }
} }
} // end RS_STACK_MUTEX(mNxsMutex); } // end RS_STACK_MUTEX(mNxsMutex);

View File

@ -114,10 +114,11 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin
/** /**
* Receive results from turtle search @see RsGenExchange @see RsNxsObserver * Receive results from turtle search @see RsGenExchange @see RsNxsObserver
* @see RsGxsNetService::receiveTurtleSearchResults
* @see p3turtle::handleSearchResult * @see p3turtle::handleSearchResult
*/ */
void receiveDistantSearchResults( TurtleRequestId id, void receiveDistantSearchResults( TurtleRequestId id,
const RsGxsGroupId& grpId ); const RsGxsGroupId& grpId ) override;
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */ /* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
virtual bool getCommentData(uint32_t token, std::vector<RsGxsComment> &msgs) virtual bool getCommentData(uint32_t token, std::vector<RsGxsComment> &msgs)