From 3fde41eb97129d3a3fda8c6d3408a3fe04868ba6 Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 16 Apr 2024 06:42:16 +0200 Subject: [PATCH] feat(web): optimized fetching more --- web/src/context.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/web/src/context.rs b/web/src/context.rs index d4d7c3b7..1d594227 100644 --- a/web/src/context.rs +++ b/web/src/context.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{collections::BTreeSet, sync::Arc}; use apb::{Activity, ActivityMut, Base, Collection, CollectionPage}; use dashmap::DashMap; @@ -166,6 +166,7 @@ impl Timeline { let mut out = self.feed(); let mut sub_tasks = Vec::new(); + let mut gonna_fetch = BTreeSet::new(); for activity in activities { // save embedded object if present @@ -175,7 +176,10 @@ impl Timeline { } } else { // try fetching it if let Some(object_id) = activity.object().id() { - sub_tasks.push(fetch_and_update("objects", object_id, auth)); + if !gonna_fetch.contains(&object_id) { + gonna_fetch.insert(object_id.clone()); + sub_tasks.push(fetch_and_update("objects", object_id, auth)); + } } } @@ -191,7 +195,10 @@ impl Timeline { if let Some(uid) = activity.actor().id() { if CACHE.get(&uid).is_none() { - sub_tasks.push(fetch_and_update("users", uid, auth)); + if !gonna_fetch.contains(&uid) { + gonna_fetch.insert(uid.clone()); + sub_tasks.push(fetch_and_update("users", uid, auth)); + } } } }