From 7059950783b8fad6b13d6f40a4dbd7886e62a7de Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Fri, 30 Aug 2024 23:06:04 +0200 Subject: [PATCH] Couple soft reset and reset start message Into a single operation when adding them to the history in the server when starting a streamed reset, instead of doing two size checks and emitting the new messages signal twice. --- src/libserver/sessionhistory.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libserver/sessionhistory.cpp b/src/libserver/sessionhistory.cpp index 259304ea39..db3159c2fc 100644 --- a/src/libserver/sessionhistory.cpp +++ b/src/libserver/sessionhistory.cpp @@ -90,6 +90,7 @@ bool SessionHistory::addMessage(const net::Message &msg) size_t bytes = msg.length(); if(hasRegularSpaceFor(bytes)) { addMessageInternal(msg, bytes); + emit newMessagesAvailable(); return true; } else { return false; @@ -101,6 +102,7 @@ bool SessionHistory::addEmergencyMessage(const net::Message &msg) uint bytes = uint(msg.length()); if(hasEmergencySpaceFor(bytes)) { addMessageInternal(msg, bytes); + emit newMessagesAvailable(); return true; } else { return false; @@ -112,7 +114,6 @@ void SessionHistory::addMessageInternal(const net::Message &msg, size_t bytes) m_sizeInBytes += bytes; ++m_lastIndex; historyAdd(msg); - emit newMessagesAvailable(); } bool SessionHistory::reset(const net::MessageList &newHistory) @@ -143,12 +144,18 @@ StreamResetStartResult SessionHistory::startStreamedReset( return StreamResetStartResult::AlreadyActive; } - if(!addMessage(net::makeSoftResetMessage(0)) || - !addMessage( - net::ServerReply::makeStreamedResetStart(ctxId, correlator))) { + net::Message softResetMsg = net::makeSoftResetMessage(0); + net::Message resetStartMsg = + net::ServerReply::makeStreamedResetStart(ctxId, correlator); + size_t softResetBytes = softResetMsg.length(); + size_t resetStartBytes = resetStartMsg.length(); + if(!hasRegularSpaceFor(softResetBytes + resetStartBytes)) { return StreamResetStartResult::OutOfSpace; } + addMessageInternal(softResetMsg, softResetBytes); + addMessageInternal(resetStartMsg, resetStartBytes); + StreamResetStartResult result = openResetStream(serverSideStateMessages); if(result == StreamResetStartResult::Ok) { m_resetStreamState = ResetStreamState::Streaming; @@ -158,6 +165,7 @@ StreamResetStartResult SessionHistory::startStreamedReset( m_resetStreamMessageCount = 0; } + emit newMessagesAvailable(); return result; }