mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
removed consts in GrpMetaCache pointers, and made it possible to always re=use cache entries, possibly updating them
This commit is contained in:
parent
506190a64b
commit
4eea5a8eca
@ -486,15 +486,13 @@ bool RsDataService::finishReleaseUpdate(int release, bool result)
|
||||
return result;
|
||||
}
|
||||
|
||||
RsGxsGrpMetaData* RsDataService::locked_getNewGrpMeta(RetroCursor &c, int colOffset)
|
||||
RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c, int colOffset,bool use_cache)
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG
|
||||
std::cerr << "RsDataService::locked_getGrpMeta()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsGxsGrpMetaData* grpMeta = new RsGxsGrpMetaData();
|
||||
|
||||
bool ok = true;
|
||||
|
||||
// for extracting raw data
|
||||
@ -505,6 +503,25 @@ RsGxsGrpMetaData* RsDataService::locked_getNewGrpMeta(RetroCursor &c, int colOff
|
||||
// grpId
|
||||
std::string tempId;
|
||||
c.getString(mColGrpMeta_GrpId + colOffset, tempId);
|
||||
|
||||
RsGxsGrpMetaData* grpMeta ;
|
||||
RsGxsGroupId grpId(tempId) ;
|
||||
|
||||
if(use_cache)
|
||||
{
|
||||
auto it = mGrpMetaDataCache.find(grpId) ;
|
||||
|
||||
if(it != mGrpMetaDataCache.end())
|
||||
grpMeta = it->second ;
|
||||
else
|
||||
{
|
||||
grpMeta = new RsGxsGrpMetaData();
|
||||
mGrpMetaDataCache[grpId] = grpMeta ;
|
||||
}
|
||||
}
|
||||
else
|
||||
grpMeta = new RsGxsGrpMetaData();
|
||||
|
||||
grpMeta->mGroupId = RsGxsGroupId(tempId);
|
||||
c.getString(mColGrpMeta_NxsIdentity + colOffset, tempId);
|
||||
grpMeta->mAuthorId = RsGxsId(tempId);
|
||||
@ -557,7 +574,8 @@ RsGxsGrpMetaData* RsDataService::locked_getNewGrpMeta(RetroCursor &c, int colOff
|
||||
return grpMeta;
|
||||
else
|
||||
{
|
||||
delete grpMeta;
|
||||
if(!use_cache)
|
||||
delete grpMeta;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -877,7 +895,7 @@ int RsDataService::storeGroup(const std::list<RsNxsGrp*>& grp)
|
||||
cv.put(KEY_GRP_STATUS, (int32_t)grpMetaPtr->mGroupStatus);
|
||||
cv.put(KEY_GRP_LAST_POST, (int32_t)grpMetaPtr->mLastPost);
|
||||
|
||||
locked_clearGrpMetaCache(grpMetaPtr->mGroupId);
|
||||
locked_updateGrpMetaCache(*grpMetaPtr);
|
||||
|
||||
if (!mDb->sqlInsert(GRP_TABLE_NAME, "", cv))
|
||||
{
|
||||
@ -893,9 +911,17 @@ int RsDataService::storeGroup(const std::list<RsNxsGrp*>& grp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void RsDataService::locked_updateGrpMetaCache(const RsGxsGrpMetaData& meta)
|
||||
{
|
||||
auto it = mGrpMetaDataCache.find(meta.mGroupId) ;
|
||||
|
||||
if(it != mGrpMetaDataCache.end())
|
||||
*(it->second) = meta ;
|
||||
}
|
||||
|
||||
void RsDataService::locked_clearGrpMetaCache(const RsGxsGroupId& gid)
|
||||
{
|
||||
std::map<RsGxsGroupId,const RsGxsGrpMetaData*>::iterator it = mGrpMetaDataCache.find(gid) ;
|
||||
auto it = mGrpMetaDataCache.find(gid) ;
|
||||
|
||||
if(it != mGrpMetaDataCache.end())
|
||||
{
|
||||
@ -973,7 +999,7 @@ int RsDataService::updateGroup(const std::list<RsNxsGrp *> &grp)
|
||||
|
||||
mDb->sqlUpdate(GRP_TABLE_NAME, "grpId='" + grpPtr->grpId.toStdString() + "'", cv);
|
||||
|
||||
locked_clearGrpMetaCache(grpMetaPtr->mGroupId);
|
||||
locked_updateGrpMetaCache(*grpMetaPtr);
|
||||
}
|
||||
// finish transaction
|
||||
bool ret = mDb->commitTransaction();
|
||||
@ -1104,7 +1130,7 @@ void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>
|
||||
if(g)
|
||||
{
|
||||
if (metaOffset) {
|
||||
g->metaData = locked_getNewGrpMeta(*c, metaOffset);
|
||||
g->metaData = locked_getGrpMeta(*c, metaOffset,false);
|
||||
}
|
||||
grps.push_back(g);
|
||||
}
|
||||
@ -1305,8 +1331,6 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
|
||||
#endif
|
||||
|
||||
grp = mGrpMetaDataCache ;
|
||||
//for(std::map<RsGxsGroupId,RsGxsGrpMetaData>::const_iterator it(mGrpMetaDataCache.begin());it!=mGrpMetaDataCache.end();++it)
|
||||
// grp[it->first] = new RsGxsGrpMetaData(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1315,11 +1339,6 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
|
||||
#endif
|
||||
// clear the cache
|
||||
|
||||
for(auto it(mGrpMetaDataCache.begin());it!=mGrpMetaDataCache.end();++it)
|
||||
delete it->second ;
|
||||
|
||||
mGrpMetaDataCache.clear();
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "", "");
|
||||
|
||||
if(c)
|
||||
@ -1328,12 +1347,11 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
|
||||
|
||||
while(valid)
|
||||
{
|
||||
RsGxsGrpMetaData* g = locked_getNewGrpMeta(*c, 0);
|
||||
RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0,true);
|
||||
|
||||
if(g)
|
||||
{
|
||||
grp[g->mGroupId] = g;
|
||||
mGrpMetaDataCache[g->mGroupId] = g ;
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << (void *)this << ": Retrieving (all) Grp metadata grpId=" << g->mGroupId << std::endl;
|
||||
#endif
|
||||
@ -1353,11 +1371,11 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::map<RsGxsGroupId, const RsGxsGrpMetaData *>::iterator mit = grp.begin();
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin();
|
||||
|
||||
for(; mit != grp.end(); ++mit)
|
||||
{
|
||||
std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::const_iterator itt = mGrpMetaDataCache.find(mit->first) ;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::const_iterator itt = mGrpMetaDataCache.find(mit->first) ;
|
||||
|
||||
if(itt != mGrpMetaDataCache.end())
|
||||
{
|
||||
@ -1385,12 +1403,11 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
|
||||
#endif
|
||||
while(valid)
|
||||
{
|
||||
RsGxsGrpMetaData* g = locked_getNewGrpMeta(*c, 0);
|
||||
RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0,true);
|
||||
|
||||
if(g)
|
||||
{
|
||||
grp[g->mGroupId] = g;
|
||||
mGrpMetaDataCache[g->mGroupId] = g ;
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
std::cerr << ". Got it. Updating cache." << std::endl;
|
||||
#endif
|
||||
|
@ -208,7 +208,7 @@ private:
|
||||
* extracts a grp meta item from a cursor at its
|
||||
* current position
|
||||
*/
|
||||
RsGxsGrpMetaData* locked_getNewGrpMeta(RetroCursor& c, int colOffset);
|
||||
RsGxsGrpMetaData* locked_getGrpMeta(RetroCursor& c, int colOffset, bool use_cache);
|
||||
|
||||
/*!
|
||||
* extracts a msg item from a cursor at its
|
||||
@ -346,8 +346,9 @@ private:
|
||||
// the entre list of grp metadata is requested (which happens quite often)
|
||||
|
||||
void locked_clearGrpMetaCache(const RsGxsGroupId& gid);
|
||||
void locked_updateGrpMetaCache(const RsGxsGrpMetaData& meta);
|
||||
|
||||
std::map<RsGxsGroupId,const RsGxsGrpMetaData*> mGrpMetaDataCache ;
|
||||
std::map<RsGxsGroupId,RsGxsGrpMetaData*> mGrpMetaDataCache ;
|
||||
bool mGrpMetaDataCache_ContainsAllDatabase ;
|
||||
};
|
||||
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
ContentValue val;
|
||||
};
|
||||
|
||||
typedef std::map<RsGxsGroupId,const RsGxsGrpMetaData*> RsGxsGrpMetaTemporaryMap;
|
||||
typedef std::map<RsGxsGroupId,RsGxsGrpMetaData*> RsGxsGrpMetaTemporaryMap;
|
||||
|
||||
/*!
|
||||
* This allows modification of local
|
||||
|
@ -2080,7 +2080,7 @@ bool RsGenExchange::processGrpMask(const RsGxsGroupId& grpId, ContentValue &grpC
|
||||
bool ok = false;
|
||||
|
||||
RsGxsGrpMetaTemporaryMap grpMetaMap;
|
||||
std::map<RsGxsGroupId, const RsGxsGrpMetaData* >::iterator mit;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData* >::iterator mit;
|
||||
grpMetaMap.insert(std::make_pair(grpId, (RsGxsGrpMetaData*)(NULL)));
|
||||
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||
@ -2362,7 +2362,7 @@ void RsGenExchange::processGroupUpdatePublish()
|
||||
{
|
||||
GroupUpdatePublish& gup = *vit;
|
||||
const RsGxsGroupId& groupId = gup.grpItem->meta.mGroupId;
|
||||
std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::iterator mit = grpMeta.find(groupId);
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.find(groupId);
|
||||
|
||||
const RsGxsGrpMetaData* meta = NULL;
|
||||
if(mit == grpMeta.end() || mit->second == NULL)
|
||||
@ -2929,7 +2929,7 @@ void RsGenExchange::processRecvdMessages()
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " deserialised info: grp id=" << meta->mGroupId << ", msg id=" << meta->mMsgId ;
|
||||
#endif
|
||||
std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " msg info : grp id=" << msg->grpId << ", msg id=" << msg->msgId << std::endl;
|
||||
@ -3186,7 +3186,7 @@ void RsGenExchange::performUpdateValidation()
|
||||
for(; vit != mGroupUpdates.end(); ++vit)
|
||||
{
|
||||
GroupUpdate& gu = *vit;
|
||||
std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::iterator mit = grpMetas.find(gu.newGrp->grpId);
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(gu.newGrp->grpId);
|
||||
gu.oldGrpMeta = mit->second;
|
||||
gu.validUpdate = updateValid(*(gu.oldGrpMeta), *(gu.newGrp));
|
||||
}
|
||||
|
@ -1016,7 +1016,7 @@ bool RsGxsDataAccess::getGroupSummary(GroupMetaReq* req)
|
||||
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
||||
|
||||
std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::iterator mit = grpMeta.begin();
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.begin();
|
||||
|
||||
for(; mit != grpMeta.end(); ++mit)
|
||||
req->mGroupMetaData.push_back(mit->second);
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
|
||||
typedef std::map< RsGxsGroupId, std::map<RsGxsMessageId, RsGxsMsgMetaData*> > MsgMetaFilter;
|
||||
typedef std::map< RsGxsGroupId, const RsGxsGrpMetaData* > GrpMetaFilter;
|
||||
typedef std::map< RsGxsGroupId, RsGxsGrpMetaData* > GrpMetaFilter;
|
||||
|
||||
class RsGxsDataAccess : public RsTokenService
|
||||
{
|
||||
|
@ -559,7 +559,7 @@ void RsGxsNetService::syncWithPeers()
|
||||
|
||||
for(RsGxsGrpMetaTemporaryMap::iterator mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
|
||||
{
|
||||
const RsGxsGrpMetaData* meta = mit->second;
|
||||
RsGxsGrpMetaData* meta = mit->second;
|
||||
|
||||
// This was commented out because we want to know how many messages are available for unsubscribed groups.
|
||||
|
||||
@ -3028,7 +3028,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
RsNxsSyncGrpItem*& grpSyncItem = *llit;
|
||||
const RsGxsGroupId& grpId = grpSyncItem->grpId;
|
||||
|
||||
std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::const_iterator metaIter = grpMetaMap.find(grpId);
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::const_iterator metaIter = grpMetaMap.find(grpId);
|
||||
bool haveItem = false;
|
||||
bool latestVersion = false;
|
||||
|
||||
|
@ -105,7 +105,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<RsGxsGroupId,const RsGxsGrpMetaData*> RsGxsGrpMetaTemporaryMap;
|
||||
typedef std::map<RsGxsGroupId,RsGxsGrpMetaData*> RsGxsGrpMetaTemporaryMap;
|
||||
typedef t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsNxsGrp> RsNxsGrpDataTemporaryMap;
|
||||
|
||||
typedef t_RsGxsGenericDataTemporaryMapVector<RsGxsMsgMetaData> RsGxsMsgMetaTemporaryMap ;
|
||||
|
Loading…
Reference in New Issue
Block a user