Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily remove delete_user until we can support larger wasms #7082

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion backend/canisters/user_index/api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions backend/canisters/user_index/impl/src/jobs/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
66 changes: 33 additions & 33 deletions backend/canisters/user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<UserMetrics> {
self.data.users.get_by_user_id(&user_id).map(|user| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CanisterId> {
self.index_map
Expand Down
22 changes: 11 additions & 11 deletions backend/canisters/user_index/impl/src/model/user_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,17 @@ impl UserMap {
self.bots.get(user_id)
}

pub fn delete_user(&mut self, user_id: UserId, now: TimestampMillis) -> Option<User> {
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<User> {
// 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backend/canisters/user_index/impl/src/updates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backend/integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading