mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
checked for existence of messages before committing to
db store in genexhange (sql error drB noted in tests) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7324 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
14b55a720c
commit
faa7a8e7b1
@ -2364,6 +2364,7 @@ void RsGenExchange::processRecvdMessages()
|
||||
|
||||
if(!msgIds.empty())
|
||||
{
|
||||
removeDeleteExistingMessages(msgs, msgIds);
|
||||
mDataStore->storeMessage(msgs);
|
||||
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_RECEIVE);
|
||||
c->msgChangeMap = msgIds;
|
||||
@ -2587,3 +2588,58 @@ void RsGenExchange::setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId
|
||||
g.val.put(RsGeneralDataService::GRP_META_CUTOFF_LEVEL, (int32_t)CutOff);
|
||||
mGrpLocMetaMap.insert(std::make_pair(token, g));
|
||||
}
|
||||
|
||||
void RsGenExchange::removeDeleteExistingMessages(
|
||||
RsGeneralDataService::MsgStoreMap& msgs, GxsMsgReq& msgIdsNotify) {
|
||||
|
||||
// first get grp ids of messages to be stored
|
||||
RsGeneralDataService::MsgStoreMap::const_iterator cit =
|
||||
msgs.begin();
|
||||
|
||||
RsGxsGroupId::std_set mGrpIdsUnique;
|
||||
|
||||
for(; cit != msgs.end(); cit++)
|
||||
{
|
||||
mGrpIdsUnique.insert(cit->second->mGroupId);
|
||||
}
|
||||
|
||||
RsGxsGroupId::std_list grpIds(mGrpIdsUnique.begin(), mGrpIdsUnique.end());
|
||||
RsGxsGroupId::std_list::const_iterator it = grpIds.begin();
|
||||
typedef std::map<RsGxsGroupId, RsGxsMessageId::std_vector> MsgIdReq;
|
||||
MsgIdReq msgIdReq;
|
||||
|
||||
// now get a list of all msgs ids for each group
|
||||
for(; it != grpIds.end(); it++)
|
||||
{
|
||||
mDataStore->retrieveMsgIds(*it, msgIdReq[*it]);
|
||||
}
|
||||
|
||||
RsGeneralDataService::MsgStoreMap::iterator cit2 = msgs.begin();
|
||||
RsGeneralDataService::MsgStoreMap filtered;
|
||||
|
||||
// now for each msg to be stored that exist in the retrieved msg/grp "index" delete and erase from map
|
||||
for(; cit2 != msgs.end(); cit2++)
|
||||
{
|
||||
const RsGxsMessageId::std_vector& msgIds = msgIdReq[cit2->second->mGroupId];
|
||||
|
||||
if(std::find(msgIds.begin(), msgIds.end(), cit2->second->mMsgId) !=
|
||||
msgIds.end())
|
||||
{
|
||||
// msg exist in retrieved index
|
||||
delete cit2->first;
|
||||
RsGxsMessageId::std_vector& notifyIds = msgIdsNotify[cit2->second->mGroupId];
|
||||
RsGxsMessageId::std_vector::iterator it2 = std::find(notifyIds.begin(),
|
||||
notifyIds.end(), cit2->second->mMsgId);
|
||||
if(it2 != notifyIds.end())
|
||||
notifyIds.erase(it2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// does not exist so add to filtered list
|
||||
filtered.insert(*cit2);
|
||||
}
|
||||
}
|
||||
|
||||
msgs = filtered;
|
||||
}
|
||||
|
||||
|
@ -771,7 +771,7 @@ private:
|
||||
|
||||
/*!
|
||||
* Checks validation of recently received groups to be
|
||||
* updated
|
||||
* updated (and updates them, a bit of a misnomer)
|
||||
*/
|
||||
void performUpdateValidation();
|
||||
|
||||
@ -790,6 +790,14 @@ private:
|
||||
*/
|
||||
bool checkKeys(const RsTlvSecurityKeySet& keySet);
|
||||
|
||||
/*!
|
||||
* Message and notification map passed to method
|
||||
* are cleansed of msgs and ids that already exist in database
|
||||
* @param msgs messages to be filtered
|
||||
* @param msgIdsNotify message notification map to be filtered
|
||||
*/
|
||||
void removeDeleteExistingMessages(RsGeneralDataService::MsgStoreMap& msgs, GxsMsgReq& msgIdsNotify);
|
||||
|
||||
private:
|
||||
|
||||
RsMutex mGenMtx;
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <util/rsrandom.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> class t_RsGenericIdType
|
||||
{
|
||||
@ -44,6 +45,7 @@ template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> c
|
||||
|
||||
typedef std::list<t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> > std_list;
|
||||
typedef std::vector<t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> > std_vector;
|
||||
typedef std::set<t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> > std_set;
|
||||
|
||||
t_RsGenericIdType()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user