Skip to content

Commit

Permalink
Remove one time job from post_upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Dec 20, 2023
1 parent e186c6a commit 03497eb
Showing 1 changed file with 1 addition and 53 deletions.
54 changes: 1 addition & 53 deletions backend/canisters/community/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use crate::activity_notifications::handle_activity_notification;
use crate::jobs::import_groups::finalize_group_import;
use crate::lifecycle::{init_env, init_state};
use crate::memory::get_upgrades_memory;
use crate::updates::c2c_join_channel::join_channel_unchecked;
use crate::{mutate_state, read_state, Data};
use crate::{read_state, Data};
use canister_logger::LogEntry;
use canister_tracing_macros::trace;
use community_canister::post_upgrade::Args;
use ic_cdk_macros::post_upgrade;
use instruction_counts_log::InstructionCountFunctionId;
use stable_memory::get_reader;
use std::time::Duration;
use tracing::info;
use types::{AccessGate, CanisterId, UserId};

#[post_upgrade]
#[trace]
Expand Down Expand Up @@ -41,52 +37,4 @@ fn post_upgrade(args: Args) {
.data
.record_instructions_count(InstructionCountFunctionId::PostUpgrade, now)
});

ic_cdk_timers::set_timer(Duration::ZERO, join_members_to_diamond_gated_channels);
}

fn join_members_to_diamond_gated_channels() {
read_state(|state| {
if state
.data
.channels
.iter()
.any(|c| c.chat.is_public.value && matches!(c.chat.gate.value, Some(AccessGate::DiamondMember)))
{
let user_ids: Vec<_> = state.data.members.iter().map(|m| m.user_id).collect();

ic_cdk::spawn(join_members_to_diamond_gated_channels_async(
state.data.local_user_index_canister_id,
user_ids,
));
}
});
}

async fn join_members_to_diamond_gated_channels_async(local_user_index_canister_id: CanisterId, user_ids: Vec<UserId>) {
if let Ok(local_user_index_canister::c2c_diamond_membership_expiry_dates::Response::Success(expiry_dates)) =
local_user_index_canister_c2c_client::c2c_diamond_membership_expiry_dates(
local_user_index_canister_id,
&local_user_index_canister::c2c_diamond_membership_expiry_dates::Args { user_ids },
)
.await
{
mutate_state(|state| {
let now = state.env.now();

for channel in state
.data
.channels
.iter_mut()
.filter(|c| c.chat.is_public.value && matches!(c.chat.gate.value, Some(AccessGate::DiamondMember)))
{
for m in state.data.members.iter_mut() {
if !m.channels.contains(&channel.id) && expiry_dates.get(&m.user_id).copied() > Some(now) {
join_channel_unchecked(channel, m, true, now);
}
}
}
handle_activity_notification(state);
})
}
}

0 comments on commit 03497eb

Please sign in to comment.