Notify one deletion per event as Cyril suggested

This commit is contained in:
Gioacchino Mazzurco 2021-01-13 17:24:03 +01:00
parent 045069c3e6
commit cef43fe048
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
5 changed files with 27 additions and 22 deletions

View File

@ -2717,10 +2717,15 @@ void RsGenExchange::processMessageDelete()
msgDeleted.push_back(note.msgIds); msgDeleted.push_back(note.msgIds);
} }
for(const auto& msgreq:msgDeleted) /* Three nested for looks like a performance bomb, but as Cyril says here
for(const auto& msgit:msgreq) * https://github.com/RetroShare/RetroShare/pull/2218#pullrequestreview-565194022
for(const auto& msg:msgit.second) * this should actually not explode at all because it is just one message at
mNotifications.push_back(new RsGxsMsgChange(RsGxsNotify::TYPE_MESSAGE_DELETED,msgit.first,msg, false)); * time that get notified */
for(const auto& msd : mMsgDeletePublish)
for(auto& msgMap : msd.mMsgs)
for(auto& msgId : msgMap.second)
mNotifications.push_back(
new RsGxsMsgDeletedChange(msgMap.first, msgId) );
mMsgDeletePublish.clear(); mMsgDeletePublish.clear();
} }

View File

@ -97,13 +97,13 @@ private:
bool mMetaChange; bool mMetaChange;
}; };
struct RsGxsBulkMsgDeletedChange : RsGxsNotify struct RsGxsMsgDeletedChange : RsGxsNotify
{ {
RsGxsBulkMsgDeletedChange( RsGxsMsgDeletedChange(
const RsGxsGroupId& gid, const std::set<RsGxsMessageId>& msgsId): const RsGxsGroupId& gid, const RsGxsMessageId& msgId):
RsGxsNotify(gid), messagesId(msgsId) {} RsGxsNotify(gid), messageId(msgId) {}
NotifyType getType() override { return TYPE_MESSAGE_DELETED; } NotifyType getType() override { return TYPE_MESSAGE_DELETED; }
const std::set<RsGxsMessageId> messagesId; const RsGxsMessageId messageId;
}; };

View File

@ -118,7 +118,7 @@ enum class RsForumEventCode: uint8_t
SYNC_PARAMETERS_UPDATED = 0x0a, /// sync and storage times have changed SYNC_PARAMETERS_UPDATED = 0x0a, /// sync and storage times have changed
PINNED_POSTS_CHANGED = 0x0b, /// some posts where pinned or un-pinned PINNED_POSTS_CHANGED = 0x0b, /// some posts where pinned or un-pinned
DELETED_FORUM = 0x0c, /// forum was deleted by cleaning DELETED_FORUM = 0x0c, /// forum was deleted by cleaning
DELETED_POSTS = 13 /// Posts deleted by cleaning DELETED_POSTS = 0x0d /// Posts deleted by cleaning
}; };
struct RsGxsForumEvent: RsEvent struct RsGxsForumEvent: RsEvent
@ -129,7 +129,7 @@ struct RsGxsForumEvent: RsEvent
RsForumEventCode mForumEventCode; RsForumEventCode mForumEventCode;
RsGxsGroupId mForumGroupId; RsGxsGroupId mForumGroupId;
std::set<RsGxsMessageId> mForumMsgsId; RsGxsMessageId mForumMsgId;
std::list<RsGxsId> mModeratorsAdded; std::list<RsGxsId> mModeratorsAdded;
std::list<RsGxsId> mModeratorsRemoved; std::list<RsGxsId> mModeratorsRemoved;
@ -141,7 +141,7 @@ struct RsGxsForumEvent: RsEvent
RsEvent::serial_process(j, ctx); RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mForumEventCode); RS_SERIAL_PROCESS(mForumEventCode);
RS_SERIAL_PROCESS(mForumGroupId); RS_SERIAL_PROCESS(mForumGroupId);
RS_SERIAL_PROCESS(mForumMsgsId); RS_SERIAL_PROCESS(mForumMsgId);
RS_SERIAL_PROCESS(mModeratorsAdded); RS_SERIAL_PROCESS(mModeratorsAdded);
RS_SERIAL_PROCESS(mModeratorsRemoved); RS_SERIAL_PROCESS(mModeratorsRemoved);
} }

View File

@ -211,7 +211,7 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
if(msgChange) /* Message received*/ if(msgChange) /* Message received*/
{ {
auto ev = std::make_shared<RsGxsForumEvent>(); auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumMsgsId.insert(msgChange->mMsgId); ev->mForumMsgId = msgChange->mMsgId;
ev->mForumGroupId = msgChange->mGroupId; ev->mForumGroupId = msgChange->mGroupId;
ev->mForumEventCode = RsForumEventCode::NEW_MESSAGE; ev->mForumEventCode = RsForumEventCode::NEW_MESSAGE;
rsEvents->postEvent(ev); rsEvents->postEvent(ev);
@ -258,8 +258,8 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
} }
case RsGxsNotify::TYPE_MESSAGE_DELETED: case RsGxsNotify::TYPE_MESSAGE_DELETED:
{ {
rs_view_ptr<RsGxsBulkMsgDeletedChange> delChange = rs_view_ptr<RsGxsMsgDeletedChange> delChange =
dynamic_cast<RsGxsBulkMsgDeletedChange*>(gxsChange); dynamic_cast<RsGxsMsgDeletedChange*>(gxsChange);
if(!delChange) if(!delChange)
{ {
@ -272,7 +272,7 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
auto ev = std::make_shared<RsGxsForumEvent>(); auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumEventCode = RsForumEventCode::DELETED_POSTS; ev->mForumEventCode = RsForumEventCode::DELETED_POSTS;
ev->mForumGroupId = delChange->mGroupId; ev->mForumGroupId = delChange->mGroupId;
ev->mForumMsgsId = delChange->messagesId; ev->mForumMsgId = delChange->messageId;
break; break;
} }
case RsGxsNotify::TYPE_GROUP_DELETED: case RsGxsNotify::TYPE_GROUP_DELETED:
@ -1053,7 +1053,7 @@ void p3GxsForums::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair&
{ {
auto ev = std::make_shared<RsGxsForumEvent>(); auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumMsgsId.insert(msgId.second); ev->mForumMsgId = msgId.second;
ev->mForumGroupId = msgId.first; ev->mForumGroupId = msgId.first;
ev->mForumEventCode = RsForumEventCode::READ_STATUS_CHANGED; ev->mForumEventCode = RsForumEventCode::READ_STATUS_CHANGED;
rsEvents->postEvent(ev); rsEvents->postEvent(ev);
@ -1084,7 +1084,7 @@ std::error_condition p3GxsForums::setPostKeepForever(
{ {
auto ev = std::make_shared<RsGxsForumEvent>(); auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumGroupId = forumId; ev->mForumGroupId = forumId;
ev->mForumMsgsId.insert(postId); ev->mForumMsgId = postId;
ev->mForumEventCode = RsForumEventCode::UPDATED_MESSAGE; ev->mForumEventCode = RsForumEventCode::UPDATED_MESSAGE;
rsEvents->postEvent(ev); rsEvents->postEvent(ev);
return std::error_condition(); return std::error_condition();

View File

@ -270,9 +270,9 @@ void NewsFeed::handleForumEvent(std::shared_ptr<const RsEvent> event)
case RsForumEventCode::UPDATED_MESSAGE: case RsForumEventCode::UPDATED_MESSAGE:
case RsForumEventCode::NEW_MESSAGE: case RsForumEventCode::NEW_MESSAGE:
for(const auto& postId: pe->mForumMsgsId)
addFeedItem(new GxsForumMsgItem( addFeedItem(new GxsForumMsgItem(
this, NEWSFEED_NEW_FORUM, pe->mForumGroupId, postId, this, NEWSFEED_NEW_FORUM,
pe->mForumGroupId, pe->mForumMsgId,
false, true )); false, true ));
break; break;