Skip to content

Commit

Permalink
Avoid double iteration when updating member expiry (#6851)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Nov 20, 2024
1 parent e1706ff commit cd9946d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add the `BotCommand` access token type ([#6830](https://github.com/open-chat-labs/open-chat/pull/6830))
- Add `bot_api_gateway` canisterId to the canister state ([#6842](https://github.com/open-chat-labs/open-chat/pull/6842))
- Simplify `inspect_message` ([#6847](https://github.com/open-chat-labs/open-chat/pull/6847))
- Avoid double iteration when updating member expiry ([#6851](https://github.com/open-chat-labs/open-chat/pull/6851))

### Removed

Expand Down
29 changes: 19 additions & 10 deletions backend/canisters/community/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use fire_and_forget_handler::FireAndForgetHandler;
use gated_groups::GatePayment;
use group_chat_core::AccessRulesInternal;
use group_community_common::{
Achievements, ExpiringMember, ExpiringMemberActions, ExpiringMembers, Members, PaymentReceipts, PaymentRecipient,
Achievements, ExpiringMember, ExpiringMemberActions, ExpiringMembers, Member, Members, PaymentReceipts, PaymentRecipient,
PendingPayment, PendingPaymentReason, PendingPaymentsQueue, UserCache,
};
use instruction_counts_log::{InstructionCountEntry, InstructionCountFunctionId, InstructionCountsLog};
Expand Down Expand Up @@ -638,20 +638,29 @@ impl Data {

if let Some(channel_id) = channel_id {
if let Some(channel) = self.channels.get_mut(&channel_id) {
user_ids = channel.chat.members.iter().map(|m| m.user_id).collect();
user_ids = channel
.chat
.members
.iter()
.filter(|m| m.can_member_lapse())
.map(|m| m.user_id)
.collect();
}
} else {
user_ids = self.members.iter().map(|m| m.user_id).collect();
user_ids = self
.members
.iter()
.filter(|m| m.can_member_lapse())
.map(|m| m.user_id)
.collect();
}

for user_id in user_ids {
if self.can_member_lapse(&user_id, channel_id) {
self.expiring_members.push(ExpiringMember {
expires: now + new_gate_expiry,
channel_id,
user_id,
});
}
self.expiring_members.push(ExpiringMember {
expires: now + new_gate_expiry,
channel_id,
user_id,
});
}
}
}
Expand Down

0 comments on commit cd9946d

Please sign in to comment.