From f2f21c3233e7bf6f5a20fbb84266fdb0ece6b071 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Wed, 18 Sep 2024 21:07:28 -0700 Subject: [PATCH] correct number of args to replies worker, recursive fetching is working Signed-off-by: sneakers-the-rat --- app/models/status.rb | 2 +- app/services/activitypub/fetch_replies_service.rb | 2 +- app/workers/fetch_reply_worker.rb | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/status.rb b/app/models/status.rb index 944352900d..2b03131fad 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -173,7 +173,7 @@ class Status < ApplicationRecord REAL_TIME_WINDOW = 6.hours # debounce fetching all replies to minimize DoS - FETCH_REPLIES_DEBOUNCE = 1.hour + FETCH_REPLIES_DEBOUNCE = 30.minutes def cache_key "v3:#{super}" diff --git a/app/services/activitypub/fetch_replies_service.rb b/app/services/activitypub/fetch_replies_service.rb index c1517837b2..18b3d2eddc 100644 --- a/app/services/activitypub/fetch_replies_service.rb +++ b/app/services/activitypub/fetch_replies_service.rb @@ -23,7 +23,7 @@ class ActivityPub::FetchRepliesService < BaseService @items = collection_items(collection_or_uri) return if @items.nil? - FetchReplyWorker.push_bulk(filtered_replies) { |reply_uri| [reply_uri, { 'request_id' => request_id }, @all_replies] } + FetchReplyWorker.push_bulk(filtered_replies) { |reply_uri| [reply_uri, { 'request_id' => request_id, 'all_replies' => @all_replies }] } # Store last fetched all to debounce @status.update(fetched_replies_at: Time.now.utc) if fetch_all_replies? diff --git a/app/workers/fetch_reply_worker.rb b/app/workers/fetch_reply_worker.rb index af33e8d681..280bc8406b 100644 --- a/app/workers/fetch_reply_worker.rb +++ b/app/workers/fetch_reply_worker.rb @@ -3,14 +3,17 @@ class FetchReplyWorker include Sidekiq::Worker include ExponentialBackoff + include JsonLdHelper sidekiq_options queue: 'pull', retry: 3 - def perform(child_url, options = {}, all_replies: false) + def perform(child_url, options = {}) + all_replies = options.delete('all_replies') + status = FetchRemoteStatusService.new.call(child_url, **options.deep_symbolize_keys) # asked to fetch replies recursively - do the second-level calls async - if all_replies && status.should_fetch_replies? + if all_replies && status json_status = fetch_resource(status.uri, true) collection = json_status['replies']