From 57d4947edfdcb005faaa98d45d7973dbe1870557 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sun, 20 Jul 2025 23:48:05 +0100 Subject: [PATCH] fix: no longer needint to wait until the cache in teh main program is filled --- src/main.rs | 100 ---------------------------------------------------- 1 file changed, 100 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6e6ad8a..e76bd34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,106 +45,6 @@ impl EventHandler for Handler { println!("Cache built successfully!"); } - async fn guild_members_chunk(&self, ctx: Context, chunk: GuildMembersChunkEvent) { - if (chunk.chunk_index + 1) == chunk.chunk_count { - // from https://github.com/serenity-rs/serenity/blob/18349f7bba43acad4261103eb38fe01d93f382df/examples/e13_parallel_loops/src/main.rs#L48 - let ctx = Arc::new(ctx); - - if !self.is_loop_running.load(Ordering::Relaxed) { - // We have to clone the Arc, as it gets moved into the new thread. - - { - // This updates all the data, wolves user data and the committees - let ctx_task = Arc::clone(&ctx); - tokio::spawn(async move { - loop { - println!("Update - Data - Start"); - - // get the data for each individual club/soc - get_wolves(&ctx_task).await; - - // get teh data for the clubs/socs committees - get_cns(&ctx_task).await; - - println!("Update - Data - End"); - tokio::time::sleep(Duration::from_secs(60 * 5)).await; - } - }); - } - - { - // this is to update member roles every 5 min - let ctx_task = Arc::clone(&ctx); - tokio::spawn(async move { - let db_lock = { - let data_read = ctx_task.data.read().await; - data_read.get::().expect("Expected Database in TypeMap.").clone() - }; - let db = db_lock.read().await; - - loop { - println!("Update - Users - Start"); - for server_config in get_server_config_bulk(&db).await { - normal::update_server(&ctx_task, &server_config, &[], &[]).await; - } - println!("Update - Users - End"); - tokio::time::sleep(Duration::from_secs(60 * 5)).await; - } - }); - } - - { - // this is to update committee roles every 5 min - let ctx_task = Arc::clone(&ctx); - tokio::spawn(async move { - loop { - println!("Update - Committee - Start"); - committee::check_committee(&ctx_task).await; - println!("Update - Committee - End"); - tokio::time::sleep(Duration::from_secs(60 * 5)).await; - } - }); - } - - { - // this updates teh server icon once a day - let ctx_task = Arc::clone(&ctx); - tokio::spawn(async move { - let db_lock = { - let data_read = ctx_task.data.read().await; - data_read.get::().expect("Expected Database in TypeMap.").clone() - }; - let db = db_lock.read().await; - let config_lock = { - let data_read = ctx.data.read().await; - data_read.get::().expect("Expected Config in TypeMap.").clone() - }; - - let config_global = config_lock.read().await; - let config_toml = get_config_icons::minimal(); - - loop { - println!("Update - Logo - Start"); - // even though this task will run every 5 min it will only actually change the icon when its a day old - if let Some(logo) = get_current_icon(&db).await { - let now = Utc::now(); - let yesterday = now.checked_sub_days(Days::new(1)).unwrap_or_default(); - if logo.date < yesterday.to_rfc3339_opts(SecondsFormat::Millis, true) { - update_icon::update_icon_main(&ctx, &db, &config_global, &config_toml).await; - } - } - println!("Update - Logo - End"); - tokio::time::sleep(Duration::from_secs(60 * 5)).await; - } - }); - } - - // Now that the loop is running, we set the bool to true - self.is_loop_running.swap(true, Ordering::Relaxed); - } - } - } - // handles previously linked accounts joining the server async fn guild_member_addition(&self, ctx: Context, new_member: Member) { let db_lock = {