Skip to content

Commit

Permalink
Push backdated user_registered events for all users
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Feb 9, 2024
1 parent e84fb71 commit a5b7e19
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
45 changes: 25 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,24 @@ candid = "0.10.3"
canister_sig_util = { git = "https://github.com/dfinity/internet-identity", rev = "f46da3bfefff638a844117606a4dea70b2dd4405" }
ciborium = "0.2.1"
clap = "4.4.8"
dfx-core = { git = "https://github.com/hpeebles/dfinity-sdk", rev = "d39dde0611fda8f30a6796b40b1dbb13a0541597" }
dfx-core = { git = "https://github.com/dfinity/sdk", rev = "c7fa9267950836fb2e8af2f03a6531ead9289f81" }
dirs = "5.0.1"
dotenv = "0.15.0"
event_sink_canister = { git = "https://github.com/open-chat-labs/event-sink", rev = "e8e4a547f767ef568ddf978c6cc421a1ef05485e" }
event_sink_client = { git = "https://github.com/open-chat-labs/event-sink", rev = "e8e4a547f767ef568ddf978c6cc421a1ef05485e" }
event_sink_client_cdk_runtime = { git = "https://github.com/open-chat-labs/event-sink", rev = "e8e4a547f767ef568ddf978c6cc421a1ef05485e" }
event_sink_utils = { git = "https://github.com/open-chat-labs/event-sink", rev = "e8e4a547f767ef568ddf978c6cc421a1ef05485e" }
event_sink_canister = { git = "https://github.com/open-chat-labs/event-sink", rev = "598a846ae880e6bb691809bae1c0839180381883" }
event_sink_client = { git = "https://github.com/open-chat-labs/event-sink", rev = "598a846ae880e6bb691809bae1c0839180381883" }
event_sink_client_cdk_runtime = { git = "https://github.com/open-chat-labs/event-sink", rev = "598a846ae880e6bb691809bae1c0839180381883" }
event_sink_utils = { git = "https://github.com/open-chat-labs/event-sink", rev = "598a846ae880e6bb691809bae1c0839180381883" }
futures = "0.3.29"
getrandom = { version = "0.2.11", features = ["custom"] }
hex = "0.4.3"
ic-agent = "0.32.0"
ic-agent = "0.33.0"
ic-cdk = "=0.12.0"
ic-cdk-macros = "0.8.4"
ic-cdk-timers = "0.6.0"
ic-ledger-types = "0.9.0"
ic-stable-structures = "0.6.2"
ic-transport-types = "0.32.0"
ic-utils = "0.32.0"
ic-transport-types = "0.33.0"
ic-utils = "0.33.0"
icrc-ledger-types = "0.1.5"
ic0 = "0.21.1"
itertools = "0.11.0"
Expand Down
21 changes: 20 additions & 1 deletion backend/canisters/user_index/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::lifecycle::{init_env, init_state};
use crate::memory::get_upgrades_memory;
use crate::{mutate_state, Data};
use crate::{mutate_state, Data, UserRegisteredEventPayload};
use canister_logger::LogEntry;
use canister_tracing_macros::trace;
use ic_cdk_macros::post_upgrade;
Expand Down Expand Up @@ -36,5 +36,24 @@ fn post_upgrade(args: Args) {

crate::jobs::sync_legacy_user_principals::start_job_if_required(state);
}

let source = Some(state.env.canister_id().to_text());

// Push an event for each user who registered before the previous upgrade
for user in state.data.users.iter().filter(|u| u.date_created < 1707486762394) {
let payload = serde_json::to_vec(&UserRegisteredEventPayload {
referred: user.referred_by.is_some(),
is_bot: user.is_bot,
})
.unwrap();

state.data.event_sink_client.push_event(event_sink_client::Event {
name: "user_registered".to_string(),
timestamp: user.date_created,
user: Some(user.user_id.to_string()),
source: source.clone(),
payload,
});
}
});
}

0 comments on commit a5b7e19

Please sign in to comment.