-) -> Result<(), LemmyError> {
- if !context.settings().federation.enabled || inboxes.is_empty() {
- return Ok(());
- }
- let activity = WithContext::new(activity);
+) -> Result<(), LemmyError>
+where
+ Activity: ActivityHandler + Serialize + Send + Sync + Clone,
+ ActorT: Actor,
+ Activity: ActivityHandler<Error = LemmyError>,
+{
+ static CACHE: Lazy<Cache<(), Arc<Vec<String>>>> = Lazy::new(|| {
+ Cache::builder()
+ .max_capacity(1)
+ .time_to_live(DEAD_INSTANCE_LIST_CACHE_DURATION)
+ .build()
+ });
+ let dead_instances = CACHE
+ .try_get_with((), async {
+ Ok::<_, diesel::result::Error>(Arc::new(Instance::dead_instances(&mut data.pool()).await?))
+ })
+ .await?;
+
+ inbox.retain(|i| {
+ let domain = i.domain().expect("has domain").to_string();
+ !dead_instances.contains(&domain)
+ });
+ info!("Sending activity {}", activity.id().to_string());
+ let activity = WithContext::new(activity, CONTEXT.deref().clone());