From 5ff58e6a5f80e2bd3a5850a01ee337f64583e4b2 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 26 Dec 2020 23:35:39 +0100 Subject: [PATCH] added params to disable the use of cache when retrieving msg and grp data and metadata. Made GxsUtil::check() not use the cache --- libretroshare/src/gxs/rsdataservice.cc | 33 +++++++++++------------- libretroshare/src/gxs/rsdataservice.h | 8 +++--- libretroshare/src/gxs/rsgds.h | 4 +-- libretroshare/src/gxs/rsgenexchange.cc | 4 +-- libretroshare/src/gxs/rsgxsnetservice.cc | 2 +- libretroshare/src/gxs/rsgxsutil.cc | 4 +-- libretroshare/src/gxstrans/p3gxstrans.cc | 2 +- 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/libretroshare/src/gxs/rsdataservice.cc b/libretroshare/src/gxs/rsdataservice.cc index ec03e76fc..2471efd0a 100644 --- a/libretroshare/src/gxs/rsdataservice.cc +++ b/libretroshare/src/gxs/rsdataservice.cc @@ -1059,7 +1059,7 @@ bool RsDataService::validSize(RsNxsGrp* grp) const return false; } -int RsDataService::retrieveNxsGrps(std::map &grp, bool withMeta, bool /* cache */) +int RsDataService::retrieveNxsGrps(std::map &grp, bool withMeta, bool cache) { #ifdef RS_DATA_SERVICE_DEBUG_TIME rstime::RsScopeTimer timer(""); @@ -1067,8 +1067,8 @@ int RsDataService::retrieveNxsGrps(std::map &grp, bool int requestedGroups = grp.size(); #endif - if(grp.empty()){ - + if(grp.empty()) + { RsStackMutex stack(mDbMutex); RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, withMeta ? mGrpColumnsWithMeta : mGrpColumns, "", ""); @@ -1076,7 +1076,7 @@ int RsDataService::retrieveNxsGrps(std::map &grp, bool { std::vector grps; - locked_retrieveGroups(c, grps, withMeta ? mColGrp_WithMetaOffset : 0); + locked_retrieveGroups(c, grps, withMeta ? mColGrp_WithMetaOffset : 0,cache); std::vector::iterator vit = grps.begin(); #ifdef RS_DATA_SERVICE_DEBUG_TIME @@ -1091,8 +1091,9 @@ int RsDataService::retrieveNxsGrps(std::map &grp, bool delete c; } - }else{ - + } + else + { RsStackMutex stack(mDbMutex); std::map::iterator mit = grp.begin(); @@ -1106,7 +1107,7 @@ int RsDataService::retrieveNxsGrps(std::map &grp, bool if(c) { std::vector grps; - locked_retrieveGroups(c, grps, withMeta ? mColGrp_WithMetaOffset : 0); + locked_retrieveGroups(c, grps, withMeta ? mColGrp_WithMetaOffset : 0,cache); if(!grps.empty()) { @@ -1138,7 +1139,7 @@ int RsDataService::retrieveNxsGrps(std::map &grp, bool return 1; } -void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector& grps, int metaOffset) +void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector& grps, int metaOffset,bool use_cache) { if(c){ bool valid = c->moveToFirst(); @@ -1150,7 +1151,7 @@ void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector if(g) { if (metaOffset) - g->metaData = new RsGxsGrpMetaData(*locked_getGrpMeta(*c, metaOffset,true)); + g->metaData = new RsGxsGrpMetaData(*locked_getGrpMeta(*c, metaOffset,use_cache)); else g->metaData = nullptr; @@ -1161,9 +1162,7 @@ void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector } } -int RsDataService::retrieveNxsMsgs( - const GxsMsgReq &reqIds, GxsMsgResult &msg, bool /* cache */, - bool withMeta ) +int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, bool withMeta, bool cache) { #ifdef RS_DATA_SERVICE_DEBUG_TIME rstime::RsScopeTimer timer(""); @@ -1186,9 +1185,7 @@ int RsDataService::retrieveNxsMsgs( RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, withMeta ? mMsgColumnsWithMeta : mMsgColumns, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", ""); if(c) - { - locked_retrieveMessages(c, msgSet, withMeta ? mColMsg_WithMetaOffset : 0); - } + locked_retrieveMessages(c, msgSet, withMeta ? mColMsg_WithMetaOffset : 0,cache); delete c; } @@ -1207,7 +1204,7 @@ int RsDataService::retrieveNxsMsgs( if(c) { - locked_retrieveMessages(c, msgSet, withMeta ? mColMsg_WithMetaOffset : 0); + locked_retrieveMessages(c, msgSet, withMeta ? mColMsg_WithMetaOffset : 0,cache); } delete c; @@ -1230,7 +1227,7 @@ int RsDataService::retrieveNxsMsgs( return 1; } -void RsDataService::locked_retrieveMessages(RetroCursor *c, std::vector &msgs, int metaOffset) +void RsDataService::locked_retrieveMessages(RetroCursor *c, std::vector &msgs, int metaOffset,bool use_cache) { bool valid = c->moveToFirst(); while(valid){ @@ -1238,7 +1235,7 @@ void RsDataService::locked_retrieveMessages(RetroCursor *c, std::vectormetaData = new RsGxsMsgMetaData(*locked_getMsgMeta(*c, metaOffset,false)); + m->metaData = new RsGxsMsgMetaData(*locked_getMsgMeta(*c, metaOffset,use_cache)); else m->metaData = nullptr; diff --git a/libretroshare/src/gxs/rsdataservice.h b/libretroshare/src/gxs/rsdataservice.h index ca975bf85..9cdd9d381 100644 --- a/libretroshare/src/gxs/rsdataservice.h +++ b/libretroshare/src/gxs/rsdataservice.h @@ -143,9 +143,7 @@ public: * @param strictFilter if true do not request any message if reqIds is empty * @return error code */ - int retrieveNxsMsgs( - const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache, - bool withMeta = false ); + int retrieveNxsMsgs( const GxsMsgReq& reqIds, GxsMsgResult& msg, bool withMeta = false, bool cache=true ); /*! * Retrieves groups, if empty, retrieves all grps, if map is not empty @@ -274,7 +272,7 @@ private: * @param c cursor to result set * @param msgs messages retrieved from cursor are stored here */ - void locked_retrieveMessages(RetroCursor* c, std::vector& msgs, int metaOffset); + void locked_retrieveMessages(RetroCursor* c, std::vector& msgs, int metaOffset, bool use_cache); /*! * Retrieves all the grp results from a cursor @@ -282,7 +280,7 @@ private: * @param grps groups retrieved from cursor are stored here * @param withMeta this initialise the metaData member of the nxsgroups retrieved */ - void locked_retrieveGroups(RetroCursor* c, std::vector& grps, int metaOffset); + void locked_retrieveGroups(RetroCursor* c, std::vector& grps, int metaOffset, bool use_cache); /*! * Retrieves all the msg meta results from a cursor diff --git a/libretroshare/src/gxs/rsgds.h b/libretroshare/src/gxs/rsgds.h index 0120770f1..6e7185805 100644 --- a/libretroshare/src/gxs/rsgds.h +++ b/libretroshare/src/gxs/rsgds.h @@ -142,9 +142,7 @@ public: * @param strictFilter if true do not request any message if reqIds is empty * @return error code */ - virtual int retrieveNxsMsgs( - const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache, - bool withMeta = false ) = 0; + virtual int retrieveNxsMsgs( const GxsMsgReq& reqIds, GxsMsgResult& msg, bool withMeta = false , bool cache=true) = 0; /*! * Retrieves all groups stored. Caller owns the memory and is supposed to delete the RsNxsGrp pointers after use. diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index b04b9aa3f..fb4fb7041 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -2802,7 +2802,7 @@ void RsGenExchange::publishGrps() RsNxsGrpDataTemporaryMap oldGrpDatas; oldGrpDatas.insert(std::make_pair(grpId, (RsNxsGrp*)NULL)); - if(mDataStore->retrieveNxsGrps(oldGrpDatas,true,false) && oldGrpDatas.size() == 1) + if(mDataStore->retrieveNxsGrps(oldGrpDatas,true,true) && oldGrpDatas.size() == 1) { auto oldGrp = oldGrpDatas[grpId]; c->mOldGroupItem = dynamic_cast(mSerialiser->deserialise(oldGrp->grp.bin_data,&oldGrp->grp.bin_len)); @@ -3330,7 +3330,7 @@ void RsGenExchange::performUpdateValidation() for(auto vit(mGroupUpdates.begin()); vit != mGroupUpdates.end(); ++vit) grpDatas.insert(std::make_pair(vit->newGrp->grpId, (RsNxsGrp*)NULL)); - if(grpDatas.empty() || !mDataStore->retrieveNxsGrps(grpDatas,true,false)) + if(grpDatas.empty() || !mDataStore->retrieveNxsGrps(grpDatas,true,true)) { if(grpDatas.empty()) RsErr() << __PRETTY_FUNCTION__ << " Validation of multiple group updates failed: no group in list!" << std::endl; diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index f2303dd06..21649e317 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -3551,7 +3551,7 @@ void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr) #endif #endif - mDataStore->retrieveNxsMsgs(msgIds, msgs, false, false); + mDataStore->retrieveNxsMsgs(msgIds, msgs, false); NxsTransaction* newTr = new NxsTransaction(); newTr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM; diff --git a/libretroshare/src/gxs/rsgxsutil.cc b/libretroshare/src/gxs/rsgxsutil.cc index aa79a2ffc..38a4a208e 100644 --- a/libretroshare/src/gxs/rsgxsutil.cc +++ b/libretroshare/src/gxs/rsgxsutil.cc @@ -233,7 +233,7 @@ bool RsGxsIntegrityCheck::check(uint16_t service_type, RsGixs *mgixs, RsGeneralD // first take out all the groups std::map grp; - mds->retrieveNxsGrps(grp, true, true); + mds->retrieveNxsGrps(grp, true, false); GxsMsgReq msgIds; GxsMsgReq grps; @@ -334,7 +334,7 @@ bool RsGxsIntegrityCheck::check(uint16_t service_type, RsGixs *mgixs, RsGeneralD // now messages GxsMsgResult msgs; - mds->retrieveNxsMsgs(grps, msgs, false, true); + mds->retrieveNxsMsgs(grps, msgs, true,false); // Check msg ids and messages. Go through all message IDs referred to by the db call // and verify that the message belongs to the nxs msg data that was just retrieved. diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index 391a38e50..fc2dd425e 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -389,7 +389,7 @@ void p3GxsTrans::GxsTransIntegrityCleanupThread::run() std::list received_msgs ; GxsMsgResult msgs; - mDs->retrieveNxsMsgs(grps, msgs, false, true); + mDs->retrieveNxsMsgs(grps, msgs, true, false); for(GxsMsgResult::iterator mit = msgs.begin();mit != msgs.end(); ++mit) {