From a71af984011ff98df2fa1b7f6c983706a91d99bf Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 17 Feb 2018 14:28:48 +0100 Subject: [PATCH] Push discovered status through streaming API within a time window (#6484) Time window of 6 hours --- app/lib/activitypub/activity.rb | 2 +- app/lib/ostatus/activity/creation.rb | 2 +- app/models/status.rb | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/lib/activitypub/activity.rb b/app/lib/activitypub/activity.rb index 0f9e4f2630..4617905c63 100644 --- a/app/lib/activitypub/activity.rb +++ b/app/lib/activitypub/activity.rb @@ -74,7 +74,7 @@ class ActivityPub::Activity # Only continue if the status is supposed to have # arrived in real-time - return unless @options[:override_timestamps] + return unless @options[:override_timestamps] || status.within_realtime_window? distribute_to_followers(status) end diff --git a/app/lib/ostatus/activity/creation.rb b/app/lib/ostatus/activity/creation.rb index b38407cd3d..7cf2d90dca 100644 --- a/app/lib/ostatus/activity/creation.rb +++ b/app/lib/ostatus/activity/creation.rb @@ -61,7 +61,7 @@ class OStatus::Activity::Creation < OStatus::Activity::Base Rails.logger.debug "Queuing remote status #{status.id} (#{id}) for distribution" LinkCrawlWorker.perform_async(status.id) unless status.spoiler_text? - DistributionWorker.perform_async(status.id) if @options[:override_timestamps] + DistributionWorker.perform_async(status.id) if @options[:override_timestamps] || status.within_realtime_window? status end diff --git a/app/models/status.rb b/app/models/status.rb index 0de89ad4e1..8186f47849 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -80,6 +80,8 @@ class Status < ApplicationRecord delegate :domain, to: :account, prefix: true + REAL_TIME_WINDOW = 6.hours + def searchable_by(preloaded = nil) ids = [account_id] @@ -108,6 +110,10 @@ class Status < ApplicationRecord !reblog_of_id.nil? end + def within_realtime_window? + created_at >= REAL_TIME_WINDOW.ago + end + def verb if destroyed? :delete