Skip to content

Commit

Permalink
Restart member migration job after importing group into community (#6940
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hpeebles authored Dec 2, 2024
1 parent 15d5b66 commit b528256
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 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/).
- Write group members to stable memory when importing group into community ([#6935](https://github.com/open-chat-labs/open-chat/pull/6935))
- Make `StableMemoryMap` use strongly typed keys ([#6937](https://github.com/open-chat-labs/open-chat/pull/6937))
- Read from stable memory members map once migration is complete ([#6938](https://github.com/open-chat-labs/open-chat/pull/6938))
- Restart member migration job after importing group into community ([#6940](https://github.com/open-chat-labs/open-chat/pull/6940))

## [[2.0.1479](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1479-community)] - 2024-11-28

Expand Down
13 changes: 12 additions & 1 deletion backend/canisters/community/impl/src/jobs/import_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ use crate::model::channels::Channel;
use crate::model::events::{CommunityEventInternal, GroupImportedInternal};
use crate::model::groups_being_imported::{GroupToImport, GroupToImportAction};
use crate::model::members::AddResult;
use crate::timer_job_types::{FinalizeGroupImportJob, ProcessGroupImportChannelMembersJob, TimerJob};
use crate::timer_job_types::{
FinalizeGroupImportJob, MigrateMembersToStableMemoryJob, ProcessGroupImportChannelMembersJob, TimerJob,
};
use crate::updates::c2c_join_channel::{add_members_to_public_channel_unchecked, join_channel_unchecked};
use crate::{mutate_state, read_state, RuntimeState};
use canister_timer_jobs::Job;
use chat_events::ChatEvents;
use constants::OPENCHAT_BOT_USER_ID;
use group_canister::c2c_export_group::{Args, Response};
Expand Down Expand Up @@ -216,6 +219,14 @@ pub(crate) fn finalize_group_import(group_id: ChatId) {
}
}

// TODO remove this once groups are upgraded and we re-enable importing
// members to stable memory
chat.members.reset_migration_to_stable_memory_complete_flag();
if !chat.members.migrate_next_batch_to_stable_memory() {
state.data.members_migrated_to_stable_memory = false;
MigrateMembersToStableMemoryJob.execute();
}

state.data.channels.add(Channel {
id: channel_id,
chat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct GroupToImport {
pub action: GroupToImportAction,
}

#[allow(dead_code)]
#[derive(Debug)]
pub enum GroupToImportAction {
Events(ChannelId, Option<EventContext>),
Expand Down Expand Up @@ -50,8 +51,9 @@ impl GroupsBeingImported {
group.current_batch_started = Some(now);
let action = if !group.events_imported {
GroupToImportAction::Events(group.channel_id, group.events_imported_up_to.clone())
} else if !group.members_imported {
GroupToImportAction::Members(group.channel_id, group.members_imported_up_to)
// TODO reinstate this once groups are upgraded
// } else if !group.members_imported {
// GroupToImportAction::Members(group.channel_id, group.members_imported_up_to)
} else {
GroupToImportAction::Core(group.bytes.len() as u64)
};
Expand Down
5 changes: 5 additions & 0 deletions backend/libraries/group_chat_core/src/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ fn default_stable_memory_members_map() -> MembersStableStorage {

#[allow(clippy::too_many_arguments)]
impl GroupMembers {
// TODO remove this once groups and communities are upgraded
pub fn reset_migration_to_stable_memory_complete_flag(&mut self) {
self.migration_to_stable_memory_complete = false;
}

pub fn migrate_next_batch_to_stable_memory(&mut self) -> bool {
if self.migration_to_stable_memory_complete {
return true;
Expand Down

0 comments on commit b528256

Please sign in to comment.