From 3c34004ce66b59cf233cdc6053f6b01722bbd701 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 11 Oct 2021 16:50:32 +1100 Subject: [PATCH] Only fetch announcements we don't already have Fixes #255. --- daemon/src/oracle.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/daemon/src/oracle.rs b/daemon/src/oracle.rs index 27479cc..2eb46e3 100644 --- a/daemon/src/oracle.rs +++ b/daemon/src/oracle.rs @@ -84,10 +84,14 @@ where } async fn update_latest_announcements(&mut self) -> Result<()> { - self.latest_announcements = next_ids() + let new_announcements = next_ids() .into_iter() + .filter(|event_id| !self.latest_announcements.contains_key(event_id)) .map(|event_id| async move { let url = event_id.to_olivia_url(); + + tracing::debug!("Fetching attestation for {}", event_id); + let response = reqwest::get(url.clone()) .await .with_context(|| format!("Failed to GET {}", url))?; @@ -103,9 +107,11 @@ where Result::<_, anyhow::Error>::Ok((event_id, announcement)) }) .collect::>() - .try_collect() + .try_collect::>() .await?; + self.latest_announcements.extend(new_announcements); // FIXME: This results in linear memory growth. + Ok(()) }