mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
trick to avoid creating new memoty when cache is not used
This commit is contained in:
parent
71f2e273ea
commit
aad542e3a5
@ -1265,12 +1265,13 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
||||
|
||||
// if vector empty then request all messages
|
||||
|
||||
t_MetaDataCache<RsGxsMessageId,RsGxsMsgMetaData>& cache(mMsgMetaDataCache[grpId]);
|
||||
// The pointer here is a trick to not initialize a new cache entry when cache is disabled, while keeping the unique variable all along.
|
||||
t_MetaDataCache<RsGxsMessageId,RsGxsMsgMetaData> *cache(mUseCache? (&mMsgMetaDataCache[grpId]) : nullptr);
|
||||
|
||||
if(msgIdV.empty())
|
||||
{
|
||||
if(mUseCache && cache.isCacheUpToDate())
|
||||
cache.getFullMetaList(msgMeta[grpId]);
|
||||
if(mUseCache && cache->isCacheUpToDate())
|
||||
cache->getFullMetaList(msgMeta[grpId]);
|
||||
else
|
||||
{
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, mMsgMetaColumns, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", "");
|
||||
@ -1280,7 +1281,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
||||
locked_retrieveMsgMetaList(c, msgMeta[grpId]);
|
||||
|
||||
if(mUseCache)
|
||||
cache.setCacheUpToDate(true);
|
||||
cache->setCacheUpToDate(true);
|
||||
}
|
||||
delete c;
|
||||
}
|
||||
@ -1297,7 +1298,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
||||
{
|
||||
const RsGxsMessageId& msgId = *sit;
|
||||
|
||||
auto meta = mUseCache?cache.getMeta(msgId): (std::shared_ptr<RsGxsMsgMetaData>());
|
||||
auto meta = mUseCache?cache->getMeta(msgId): (std::shared_ptr<RsGxsMsgMetaData>());
|
||||
|
||||
if(meta)
|
||||
metaSet.push_back(meta);
|
||||
|
Loading…
Reference in New Issue
Block a user