]> Untitled Git - lemmy.git/commitdiff
Fetch community outbox and moderators in parallel (#3360)
authorNutomic <me@nutomic.com>
Mon, 26 Jun 2023 16:14:50 +0000 (18:14 +0200)
committerGitHub <noreply@github.com>
Mon, 26 Jun 2023 16:14:50 +0000 (12:14 -0400)
This will speedup first time fetching of a remote community

crates/apub/src/objects/community.rs

index 888a7f4581b60c7d7af51ee0d10039ace140a0ec..17476e9f8c5fcac5f5e0b769524743ef0fd17ac2 100644 (file)
@@ -140,19 +140,16 @@ impl Object for ApubCommunity {
 
     // Fetching mods and outbox is not necessary for Lemmy to work, so ignore errors. Besides,
     // we need to ignore these errors so that tests can work entirely offline.
-    group
-      .outbox
-      .dereference(&community, context)
-      .await
-      .map_err(|e| debug!("{}", e))
-      .ok();
+    let fetch_outbox = group.outbox.dereference(&community, context);
 
     if let Some(moderators) = group.attributed_to {
-      moderators
-        .dereference(&community, context)
-        .await
-        .map_err(|e| debug!("{}", e))
-        .ok();
+      let fetch_moderators = moderators.dereference(&community, context);
+      // Fetch mods and outbox in parallel
+      let res = tokio::join!(fetch_outbox, fetch_moderators);
+      res.0.map_err(|e| debug!("{}", e)).ok();
+      res.1.map_err(|e| debug!("{}", e)).ok();
+    } else {
+      fetch_outbox.await.map_err(|e| debug!("{}", e)).ok();
     }
 
     Ok(community)