From 13ead50593667a22cf6fa68bcb7b5cce491fb1f7 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Mon, 18 Nov 2024 12:05:29 +0000 Subject: [PATCH] Avoid storing any events on the heap within direct chats (#6838) --- backend/canisters/user/CHANGELOG.md | 1 + backend/libraries/chat_events/src/hybrid_map.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/canisters/user/CHANGELOG.md b/backend/canisters/user/CHANGELOG.md index fa3432ffc8..673b89a5bf 100644 --- a/backend/canisters/user/CHANGELOG.md +++ b/backend/canisters/user/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Add cycles balance check to more timer jobs ([#6822](https://github.com/open-chat-labs/open-chat/pull/6822)) - Avoid iterating all events when migrating private replies after group import ([#6827](https://github.com/open-chat-labs/open-chat/pull/6827)) - Add the `BotCommand` access token type ([#6830](https://github.com/open-chat-labs/open-chat/pull/6830)) +- Avoid storing any events on the heap within direct chats ([#6838](https://github.com/open-chat-labs/open-chat/pull/6838)) ### Removed diff --git a/backend/libraries/chat_events/src/hybrid_map.rs b/backend/libraries/chat_events/src/hybrid_map.rs index 462e3411b5..b36a04d42c 100644 --- a/backend/libraries/chat_events/src/hybrid_map.rs +++ b/backend/libraries/chat_events/src/hybrid_map.rs @@ -47,12 +47,15 @@ impl HybridMap { impl EventsMap for HybridMap { fn new(chat: Chat, thread_root_message_index: Option) -> Self { + let disable_fast_map = matches!(chat, Chat::Direct(_)) || thread_root_message_index.is_some(); + let max_events_in_fast_map = if disable_fast_map { 0 } else { 1000 }; + HybridMap { fast: BTreeMap::new(), slow: MSlow::new(chat, thread_root_message_index), latest_event_index: EventIndex::default(), // Don't store thread events on the heap - max_events_in_fast_map: if thread_root_message_index.is_none() { 1000 } else { 0 }, + max_events_in_fast_map, } }