diff --git a/backend/canisters/online_users/CHANGELOG.md b/backend/canisters/online_users/CHANGELOG.md index 47e9a8e9c9..514d87ef2e 100644 --- a/backend/canisters/online_users/CHANGELOG.md +++ b/backend/canisters/online_users/CHANGELOG.md @@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added `c2c_remove_user` to be called by the UserIndex ([#6179](https://github.com/open-chat-labs/open-chat/pull/6179)) +### Changed + +- Clear the principal to userId map to ensure latest values are used ([#6184](https://github.com/open-chat-labs/open-chat/pull/6184)) + ## [[2.0.1149](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1149-online_users)] - 2024-04-23 ### Changed diff --git a/backend/canisters/online_users/impl/src/lifecycle/post_upgrade.rs b/backend/canisters/online_users/impl/src/lifecycle/post_upgrade.rs index 7ba1c36fda..a434762fb0 100644 --- a/backend/canisters/online_users/impl/src/lifecycle/post_upgrade.rs +++ b/backend/canisters/online_users/impl/src/lifecycle/post_upgrade.rs @@ -1,6 +1,6 @@ use crate::lifecycle::{init_env, init_state}; use crate::memory::get_upgrades_memory; -use crate::Data; +use crate::{mutate_state, Data}; use canister_logger::LogEntry; use canister_tracing_macros::trace; use ic_cdk::post_upgrade; @@ -24,4 +24,7 @@ fn post_upgrade(args: Args) { init_state(env, data, args.wasm_version); info!(version = %args.wasm_version, "Post-upgrade complete"); + + // TODO remove this after upgrade + mutate_state(|state| state.data.principal_to_user_id_map.clear()); } diff --git a/backend/canisters/online_users/impl/src/model/principal_to_user_id_map.rs b/backend/canisters/online_users/impl/src/model/principal_to_user_id_map.rs index 8ca331ceeb..ac3b13fe16 100644 --- a/backend/canisters/online_users/impl/src/model/principal_to_user_id_map.rs +++ b/backend/canisters/online_users/impl/src/model/principal_to_user_id_map.rs @@ -22,6 +22,10 @@ impl PrincipalToUserIdMap { pub fn remove(&mut self, principal: &Principal) -> Option { self.map.remove(principal).map(|u| u.into()) } + + pub fn clear(&mut self) { + self.map.clear_new() + } } fn init_map() -> StableBTreeMap {