From 3db12e4196568d73f7e2d591602aac072974b067 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Wed, 18 Dec 2024 22:16:46 +0000 Subject: [PATCH] Temporarily remove `delete_user` until we can support larger wasms (#7082) --- backend/canisters/user_index/CHANGELOG.md | 1 + backend/canisters/user_index/api/src/main.rs | 1 - .../canisters/user_index/impl/src/jobs/mod.rs | 4 +- backend/canisters/user_index/impl/src/lib.rs | 66 +++++++++---------- .../impl/src/model/local_user_index_map.rs | 22 +++---- .../user_index/impl/src/model/user_map.rs | 22 +++---- .../impl/src/updates/c2c_notify_events.rs | 22 +++---- .../user_index/impl/src/updates/mod.rs | 2 +- backend/integration_tests/src/lib.rs | 2 +- 9 files changed, 71 insertions(+), 71 deletions(-) diff --git a/backend/canisters/user_index/CHANGELOG.md b/backend/canisters/user_index/CHANGELOG.md index a505d13d8c..450c0cd795 100644 --- a/backend/canisters/user_index/CHANGELOG.md +++ b/backend/canisters/user_index/CHANGELOG.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Removed - Remove bot thread permissions ([#7071](https://github.com/open-chat-labs/open-chat/pull/7071)) +- Temporarily remove `delete_user` until we can support larger wasms ([#7082](https://github.com/open-chat-labs/open-chat/pull/7082)) ## [[2.0.1508](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1508-user_index)] - 2024-12-13 diff --git a/backend/canisters/user_index/api/src/main.rs b/backend/canisters/user_index/api/src/main.rs index 41e7f0c8e5..2dc4afe948 100644 --- a/backend/canisters/user_index/api/src/main.rs +++ b/backend/canisters/user_index/api/src/main.rs @@ -54,7 +54,6 @@ fn main() { generate_ts_method!(user_index, users_chit); generate_ts_method!(user_index, update_diamond_membership_subscription); - generate_ts_method!(user_index, delete_user); generate_ts_method!(user_index, pay_for_diamond_membership); generate_ts_method!(user_index, register_bot); generate_ts_method!(user_index, set_diamond_membership_fees); diff --git a/backend/canisters/user_index/impl/src/jobs/mod.rs b/backend/canisters/user_index/impl/src/jobs/mod.rs index a0f58f4380..e6e70d0786 100644 --- a/backend/canisters/user_index/impl/src/jobs/mod.rs +++ b/backend/canisters/user_index/impl/src/jobs/mod.rs @@ -1,6 +1,6 @@ use crate::RuntimeState; pub mod make_pending_payments; -pub mod remove_from_online_users_canister; +// pub mod remove_from_online_users_canister; pub mod reset_leaderboard; pub mod submit_message_to_modclub; pub mod sync_events_to_local_user_index_canisters; @@ -9,7 +9,7 @@ pub mod upgrade_canisters; pub(crate) fn start(state: &RuntimeState) { make_pending_payments::start_job_if_required(state); - remove_from_online_users_canister::start_job_if_required(state); + // remove_from_online_users_canister::start_job_if_required(state); submit_message_to_modclub::start_job_if_required(state); sync_events_to_local_user_index_canisters::start_job_if_required(state); sync_users_to_identity_canister::start_job_if_required(state); diff --git a/backend/canisters/user_index/impl/src/lib.rs b/backend/canisters/user_index/impl/src/lib.rs index bc5e6dfeca..d392872126 100644 --- a/backend/canisters/user_index/impl/src/lib.rs +++ b/backend/canisters/user_index/impl/src/lib.rs @@ -7,7 +7,7 @@ use candid::Principal; use canister_state_macros::canister_state; use canister_timer_jobs::TimerJobs; use constants::DAY_IN_MS; -use event_store_producer::{EventBuilder, EventStoreClient, EventStoreClientBuilder, EventStoreClientInfo}; +use event_store_producer::{EventStoreClient, EventStoreClientBuilder, EventStoreClientInfo}; use event_store_producer_cdk_runtime::CdkRuntime; use fire_and_forget_handler::FireAndForgetHandler; use icrc_ledger_types::icrc1::account::{Account, Subaccount}; @@ -162,38 +162,38 @@ impl RuntimeState { jobs::submit_message_to_modclub::start_job_if_required(self); } - pub fn delete_user(&mut self, user_id: UserId, triggered_by_user: bool) { - let now = self.env.now(); - if let Some(user) = self.data.users.delete_user(user_id, now) { - self.data.local_index_map.remove_user(&user_id); - self.data.empty_users.remove(&user_id); - - #[derive(Serialize)] - struct EventPayload { - triggered_by_user: bool, - } - - self.data.event_store_client.push( - EventBuilder::new("user_deleted", now) - .with_user(user_id.to_string(), true) - .with_source(self.env.canister_id().to_string(), false) - .with_json_payload(&EventPayload { triggered_by_user }) - .build(), - ); - - self.data.deleted_users.push(DeletedUser { - user_id, - triggered_by_user, - timestamp: now, - }); - - self.data.identity_canister_user_sync_queue.push_back((user.principal, None)); - jobs::sync_users_to_identity_canister::try_run_now(self); - - self.data.remove_from_online_users_queue.push_back(user.principal); - jobs::remove_from_online_users_canister::start_job_if_required(self); - } - } + // pub fn delete_user(&mut self, user_id: UserId, triggered_by_user: bool) { + // let now = self.env.now(); + // if let Some(user) = self.data.users.delete_user(user_id, now) { + // self.data.local_index_map.remove_user(&user_id); + // self.data.empty_users.remove(&user_id); + // + // #[derive(Serialize)] + // struct EventPayload { + // triggered_by_user: bool, + // } + // + // self.data.event_store_client.push( + // EventBuilder::new("user_deleted", now) + // .with_user(user_id.to_string(), true) + // .with_source(self.env.canister_id().to_string(), false) + // .with_json_payload(&EventPayload { triggered_by_user }) + // .build(), + // ); + // + // self.data.deleted_users.push(DeletedUser { + // user_id, + // triggered_by_user, + // timestamp: now, + // }); + // + // self.data.identity_canister_user_sync_queue.push_back((user.principal, None)); + // jobs::sync_users_to_identity_canister::try_run_now(self); + // + // self.data.remove_from_online_users_queue.push_back(user.principal); + // jobs::remove_from_online_users_canister::start_job_if_required(self); + // } + // } pub fn user_metrics(&self, user_id: UserId) -> Option { self.data.users.get_by_user_id(&user_id).map(|user| { diff --git a/backend/canisters/user_index/impl/src/model/local_user_index_map.rs b/backend/canisters/user_index/impl/src/model/local_user_index_map.rs index a5648ccdd6..cdd304e9c3 100644 --- a/backend/canisters/user_index/impl/src/model/local_user_index_map.rs +++ b/backend/canisters/user_index/impl/src/model/local_user_index_map.rs @@ -44,17 +44,17 @@ impl LocalUserIndexMap { false } - pub fn remove_user(&mut self, user_id: &UserId) -> bool { - if let Some(index) = self.user_to_index.remove(user_id) { - self.index_map - .entry(index) - .and_modify(|i| i.user_count = i.user_count.saturating_sub(1)); - - true - } else { - false - } - } + // pub fn remove_user(&mut self, user_id: &UserId) -> bool { + // if let Some(index) = self.user_to_index.remove(user_id) { + // self.index_map + // .entry(index) + // .and_modify(|i| i.user_count = i.user_count.saturating_sub(1)); + // + // true + // } else { + // false + // } + // } pub fn index_for_new_user(&self) -> Option { self.index_map diff --git a/backend/canisters/user_index/impl/src/model/user_map.rs b/backend/canisters/user_index/impl/src/model/user_map.rs index 80d5f7e449..c885a3b0fe 100644 --- a/backend/canisters/user_index/impl/src/model/user_map.rs +++ b/backend/canisters/user_index/impl/src/model/user_map.rs @@ -223,17 +223,17 @@ impl UserMap { self.bots.get(user_id) } - pub fn delete_user(&mut self, user_id: UserId, now: TimestampMillis) -> Option { - let user = self.users.remove(&user_id)?; - if self.principal_to_user_id.get(&user.principal) == Some(&user_id) { - self.principal_to_user_id.remove(&user.principal); - } - if self.username_to_user_id.get(&user.username) == Some(&user_id) { - self.username_to_user_id.remove(&user.username); - } - self.deleted_users.insert(user_id, now); - Some(user) - } + // pub fn delete_user(&mut self, user_id: UserId, now: TimestampMillis) -> Option { + // let user = self.users.remove(&user_id)?; + // if self.principal_to_user_id.get(&user.principal) == Some(&user_id) { + // self.principal_to_user_id.remove(&user.principal); + // } + // if self.username_to_user_id.get(&user.username) == Some(&user_id) { + // self.username_to_user_id.remove(&user.username); + // } + // self.deleted_users.insert(user_id, now); + // Some(user) + // } pub fn is_deleted(&self, user_id: &UserId) -> bool { self.deleted_users.contains_key(user_id) && !self.users.contains_key(user_id) diff --git a/backend/canisters/user_index/impl/src/updates/c2c_notify_events.rs b/backend/canisters/user_index/impl/src/updates/c2c_notify_events.rs index 04c5b5a47c..21bea57883 100644 --- a/backend/canisters/user_index/impl/src/updates/c2c_notify_events.rs +++ b/backend/canisters/user_index/impl/src/updates/c2c_notify_events.rs @@ -5,8 +5,8 @@ use canister_api_macros::update; use canister_tracing_macros::trace; use event_store_producer::EventBuilder; use local_user_index_canister::{ - DeleteUser, OpenChatBotMessage, OpenChatBotMessageV2, UserIndexEvent, UserJoinedCommunityOrChannel, UserJoinedGroup, - UserRegistered, UsernameChanged, + OpenChatBotMessage, OpenChatBotMessageV2, UserIndexEvent, UserJoinedCommunityOrChannel, UserJoinedGroup, UserRegistered, + UsernameChanged, }; use storage_index_canister::add_or_update_users::UserConfig; use types::{CanisterId, MessageContent, TextContent, TimestampMillis, UserId, UserType}; @@ -78,15 +78,15 @@ fn handle_event(event: LocalUserIndexEvent, caller: Principal, now: TimestampMil })), ); } - LocalUserIndexEvent::UserDeleted(ev) => { - state.delete_user(ev.user_id, false); - state.push_event_to_all_local_user_indexes( - UserIndexEvent::DeleteUser(DeleteUser { - user_id: ev.user_id, - triggered_by_user: false, - }), - Some(caller), - ); + LocalUserIndexEvent::UserDeleted(_) => { + // state.delete_user(ev.user_id, false); + // state.push_event_to_all_local_user_indexes( + // UserIndexEvent::DeleteUser(DeleteUser { + // user_id: ev.user_id, + // triggered_by_user: false, + // }), + // Some(caller), + // ); } LocalUserIndexEvent::NotifyUniquePersonProof(ev) => { let (user_id, proof) = *ev; diff --git a/backend/canisters/user_index/impl/src/updates/mod.rs b/backend/canisters/user_index/impl/src/updates/mod.rs index a16cbaaf60..218296e0c5 100644 --- a/backend/canisters/user_index/impl/src/updates/mod.rs +++ b/backend/canisters/user_index/impl/src/updates/mod.rs @@ -11,7 +11,7 @@ pub mod c2c_report_message; pub mod c2c_send_openchat_bot_messages; pub mod c2c_set_avatar; pub mod c2c_suspend_users; -pub mod delete_user; +// pub mod delete_user; pub mod mark_local_user_index_full; pub mod mark_suspected_bot; pub mod modclub_callback; diff --git a/backend/integration_tests/src/lib.rs b/backend/integration_tests/src/lib.rs index 5bc4c7b80f..2a9657dc7a 100644 --- a/backend/integration_tests/src/lib.rs +++ b/backend/integration_tests/src/lib.rs @@ -18,7 +18,7 @@ mod cycles_dispenser_tests; mod delete_direct_chat_tests; mod delete_group_tests; mod delete_message_tests; -mod delete_user_tests; +// mod delete_user_tests; mod diamond_membership_tests; mod disappearing_message_tests; mod edit_message_tests;