Skip to content

Commit b39e64f

Browse files
committed
avoid reiterate all the pools
1 parent f278c76 commit b39e64f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

rewards/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ decl_module! {
8585
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
8686

8787
fn on_initialize(now: T::BlockNumber) -> Weight {
88+
let mut count = 0;
8889
T::Handler::accumulate_reward(now, | pool, reward_to_accumulate | {
8990
if !reward_to_accumulate.is_zero() {
91+
count += 1;
9092
Pools::<T>::mutate(pool, | pool_info | pool_info.total_rewards = pool_info.total_rewards.saturating_add(reward_to_accumulate));
9193
}
9294
});
93-
T::WeightInfo::on_initialize(Pools::<T>::iter().count() as u32)
95+
T::WeightInfo::on_initialize(count)
9496
}
9597
}
9698
}

0 commit comments

Comments
 (0)