perf(chat): single-pass watermark and move-append on chat load
Loading chat history did more work than it needed to. Seeding the unread watermark walked every conversation and copied each one's full message list out of the store just to read the last timestamp, and the database reload copied every message into the store one at a time with no reservation. - The watermark now comes from one pass over the stored messages that returns the latest timestamp per conversation, with no per- conversation copy or sort. - The store gained a move-append and a reserve, so the reload pre-sizes its vector and dedup set once and moves each row in instead of copying it. The dedup key is computed before the move. Behaviour is unchanged: the watermark values and the blocked-conversation filter on reload are the same as before. Tests cover the per-conversation latest-timestamp pass and move-append. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+2
-4
@@ -4091,10 +4091,8 @@ void App::provisionChatIdentityFromSecret(std::string secret)
|
||||
// Baseline unread: treat everything already in the store at load as read, so only messages
|
||||
// that arrive while the app is open badge as unread (Q1).
|
||||
const auto& store = chat_service_.store();
|
||||
for (const auto& cid : store.conversationIds()) {
|
||||
const auto msgs = store.conversation(cid);
|
||||
if (!msgs.empty()) chat_seen_watermark_[cid] = msgs.back().timestamp;
|
||||
}
|
||||
for (const auto& [cid, ts] : store.latestTimestampByConversation())
|
||||
chat_seen_watermark_[cid] = ts;
|
||||
}
|
||||
} else {
|
||||
chat_identity_unavailable_ = true;
|
||||
|
||||
Reference in New Issue
Block a user