From bd9a8ae3aa398d2cfdeadddf363d1b6add928d18 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 9 May 2017 22:39:15 +0200 Subject: [PATCH] prevent to remove old forum messages that have follow-ups. --- libretroshare/src/gxs/rsgxsutil.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsutil.cc b/libretroshare/src/gxs/rsgxsutil.cc index f37ed67ba..21d7d3d3e 100644 --- a/libretroshare/src/gxs/rsgxsutil.cc +++ b/libretroshare/src/gxs/rsgxsutil.cc @@ -82,14 +82,23 @@ bool RsGxsMessageCleanUp::clean() for(; mit != result.end(); ++mit) { std::vector& metaV = mit->second; - std::vector::iterator vit = metaV.begin(); - for(; vit != metaV.end(); ) + // First, make a map of which message have a child message. This allows to only delete messages that dont have child messages. + // A more accurate way to go would be to compute the time of the oldest message and possibly delete all the branch, but in the + // end the message tree will be deleted slice after slice, which should still be reasonnably fast. + // + std::set messages_with_kids ; + + for( uint32_t i=0;imParentId.isNull()) + messages_with_kids.insert(metaV[i]->mParentId) ; + + for( uint32_t i=0;i 0 && (meta->mPublishTs + store_period) < now; + bool remove = store_period > 0 && ((meta->mPublishTs + store_period) < now) && (messages_with_kids.find(meta->mMsgId)==messages_with_kids.end()); // check client does not want the message kept regardless of age remove &= !(meta->mMsgStatus & GXS_SERV::GXS_MSG_STATUS_KEEP); @@ -106,7 +115,6 @@ bool RsGxsMessageCleanUp::clean() } delete meta; - vit = metaV.erase(vit); } }