Skip to content

Commit

Permalink
correct number of args to replies worker, recursive fetching is working
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakers-the-rat committed Sep 19, 2024
1 parent db2107e commit 39ac978
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,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}"
Expand Down
2 changes: 1 addition & 1 deletion app/services/activitypub/fetch_replies_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def call(parent_status, collection_or_uri, allow_synchronous_requests: true, req
@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?

Expand Down
7 changes: 5 additions & 2 deletions app/workers/fetch_reply_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 39ac978

Please sign in to comment.