diff --git a/crates/federate/src/inboxes.rs b/crates/federate/src/inboxes.rs index 6519a7dd2..17dac65f4 100644 --- a/crates/federate/src/inboxes.rs +++ b/crates/federate/src/inboxes.rs @@ -92,6 +92,10 @@ impl CommunityInboxCollector { .send_inboxes .iter() .filter_map(std::option::Option::as_ref) + // a similar filter also happens within the activitypub-federation crate. but that filter + // happens much later - by doing it here, we can ensure that in the happy case, this + // function returns 0 urls which means the system doesn't have to create a tokio + // task for sending at all (since that task has a fair amount of overhead) .filter(|&u| (u.domain() == Some(&self.domain))) .map(|u| u.inner().clone()), ); diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index a6783c2fc..12371e06f 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -8,9 +8,7 @@ use crate::{ WORK_FINISHED_RECHECK_DELAY, }, }; -use activitypub_federation::{ - config::{FederationConfig}, -}; +use activitypub_federation::config::FederationConfig; use anyhow::{Context, Result}; use chrono::{DateTime, Days, TimeZone, Utc}; use lemmy_api_common::{ @@ -119,11 +117,9 @@ impl InstanceWorker { let next_id_to_send = ActivityId(last_sent_id.0 + 1); { // sanity check: calculate next id to send based on the last id and the in flight requests - let last_successful_id = self - .state - .last_successful_id - .map(|e| e.0) - .expect("set above"); + let last_successful_id = self.state.last_successful_id.map(|e| e.0).context( + "impossible: id is initialized in get_latest_ids and never returned to None", + )?; let expected_next_id = last_successful_id + (successfuls.len() as i64) + in_flight + 1; // compare to next id based on incrementing if expected_next_id != next_id_to_send.0 {