From c64a95094ffd7a2876f03547e633fac4d42520d1 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Mon, 17 Feb 2020 12:15:11 -0500 Subject: [PATCH] Conservatively announce rating changes --- youmubot-cf/src/announcer.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/youmubot-cf/src/announcer.rs b/youmubot-cf/src/announcer.rs index 3c1e837..2cab8eb 100644 --- a/youmubot-cf/src/announcer.rs +++ b/youmubot-cf/src/announcer.rs @@ -46,11 +46,7 @@ fn update_user( .next() .ok_or(CommandError::from("Not found"))?; - let rating_changes = { - let mut v = info.rating_changes(reqwest)?; - v.reverse(); - v - }; + let rating_changes = info.rating_changes(reqwest)?; let mut channels_list: Option> = None; cfu.last_update = Utc::now(); @@ -86,10 +82,17 @@ fn update_user( let rating_changes = match cfu.last_contest_id { None => rating_changes, - Some(v) => rating_changes - .into_iter() - .take_while(|rc| rc.contest_id != v) - .collect(), + Some(v) => { + let mut v: Vec<_> = rating_changes + .into_iter() + // Skip instead of take because sometimes Codeforces + // performs rollback. + .skip_while(|rc| rc.contest_id != v) + .skip(1) + .collect(); + v.reverse(); + v + } }; cfu.last_contest_id = rating_changes