From 5ba963305c4b080caa0c9bbe2017729ac93581fe Mon Sep 17 00:00:00 2001 From: Neshura Date: Mon, 18 Dec 2023 11:24:02 +0100 Subject: [PATCH] Deduplicate Config reload logging --- src/bot/mod.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/bot/mod.rs b/src/bot/mod.rs index e6c92b5..8c1a5fa 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -69,7 +69,10 @@ pub(crate) async fn run(data: Arc>) { Ok(data) => data, Err(e) => panic!("{}", e), }; - write.messages.push(Message::Info("Config reloaded".to_string())); + let message = Message::Info("Config reloaded".to_string()); + if !write.messages.contains(&message) { + write.messages.push(message); + }; } } @@ -102,9 +105,12 @@ pub(crate) async fn run(data: Arc>) { continue } }; - drop(read); - let mut write = data.write().await; - write.messages.push(Message::Info("Communities reloaded".to_string())); + let message = Message::Info("Communities reloaded".to_string()); + if !read.messages.contains(&message) { + drop(read); + let mut write = data.write().await; + write.messages.push(message); + }; last_reload = Utc::now(); } } @@ -199,10 +205,11 @@ async fn handle_series( { let read = data.read().await; if read.post_history.check_for_post(series.slug.as_str(), post_part_info.as_string().as_str(), post_lemmy_info.title.as_str()) { - if !read.messages.contains(&Message::Info(format!("Skipping '{}' since already posted", post_lemmy_info.title))) { + let message = Message::Info(format!("Skipping '{}' since already posted", post_lemmy_info.title)); + if !read.messages.contains(&message) { drop(read); let mut write = data.write().await; - write.messages.push(Message::Info(format!("Skipping '{}' since already posted", post_lemmy_info.title))); + write.messages.push(message); }; post_list.remove(index); continue