Skip to content

Commit

Permalink
Avoid storing any events on the heap within direct chats (#6838)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Nov 18, 2024
1 parent 521176b commit 13ead50
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/canisters/user/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion backend/libraries/chat_events/src/hybrid_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ impl HybridMap<ChatEventsStableStorage> {

impl<MSlow: EventsMap> EventsMap for HybridMap<MSlow> {
fn new(chat: Chat, thread_root_message_index: Option<MessageIndex>) -> 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,
}
}

Expand Down

0 comments on commit 13ead50

Please sign in to comment.