From 47b10107c57f55e99ed64896d4cfdfdec5a4276a Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Tue, 12 Nov 2024 20:03:24 +0000 Subject: [PATCH] Only recalculate the queue if it is empty (#6798) --- .../impl/src/jobs/topup_canisters.rs | 19 +++++++++++-------- .../local_group_index/impl/src/lib.rs | 1 + .../impl/src/jobs/topup_canisters.rs | 5 ++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/backend/canisters/local_group_index/impl/src/jobs/topup_canisters.rs b/backend/canisters/local_group_index/impl/src/jobs/topup_canisters.rs index e048e3314d..b8169164ed 100644 --- a/backend/canisters/local_group_index/impl/src/jobs/topup_canisters.rs +++ b/backend/canisters/local_group_index/impl/src/jobs/topup_canisters.rs @@ -23,15 +23,18 @@ pub fn start_job() { fn populate_canisters() { mutate_state(|state| { - state.data.cycles_balance_check_queue = VecDeque::from_iter( - state - .data - .local_communities - .iter() - .map(|(c, _)| CanisterId::from(*c)) - .chain(state.data.local_groups.iter().map(|(g, _)| CanisterId::from(*g))), - ); + if state.data.cycles_balance_check_queue.is_empty() { + state.data.cycles_balance_check_queue = VecDeque::from_iter( + state + .data + .local_communities + .iter() + .map(|(c, _)| CanisterId::from(*c)) + .chain(state.data.local_groups.iter().map(|(g, _)| CanisterId::from(*g))), + ); + } }); + if let Some(timer_id) = TIMER_ID.take() { ic_cdk_timers::clear_timer(timer_id); } diff --git a/backend/canisters/local_group_index/impl/src/lib.rs b/backend/canisters/local_group_index/impl/src/lib.rs index 4d49d62a46..934e04dc21 100644 --- a/backend/canisters/local_group_index/impl/src/lib.rs +++ b/backend/canisters/local_group_index/impl/src/lib.rs @@ -170,6 +170,7 @@ struct Data { pub event_deduper: EventDeduper, pub rng_seed: [u8; 32], pub canisters_pending_events_migration_to_stable_memory: Vec, + #[serde(default)] pub cycles_balance_check_queue: VecDeque, } diff --git a/backend/canisters/local_user_index/impl/src/jobs/topup_canisters.rs b/backend/canisters/local_user_index/impl/src/jobs/topup_canisters.rs index 51fec45b00..917c090b59 100644 --- a/backend/canisters/local_user_index/impl/src/jobs/topup_canisters.rs +++ b/backend/canisters/local_user_index/impl/src/jobs/topup_canisters.rs @@ -23,8 +23,11 @@ pub fn start_job() { fn populate_canisters() { mutate_state(|state| { - state.data.cycles_balance_check_queue = VecDeque::from_iter(state.data.local_users.iter().map(|(u, _)| *u)) + if state.data.cycles_balance_check_queue.is_empty() { + state.data.cycles_balance_check_queue = VecDeque::from_iter(state.data.local_users.iter().map(|(u, _)| *u)); + } }); + if let Some(timer_id) = TIMER_ID.take() { ic_cdk_timers::clear_timer(timer_id); }