Skip to content

Commit

Permalink
Refactor status reference flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 15, 2023
1 parent 71c451a commit a39b8cb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
5 changes: 1 addition & 4 deletions app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,7 @@ def process_references!
quote = @object['quote'] || @object['quoteUrl'] || @object['quoteURL'] || @object['_misskey_quote']
references << quote if quote

return unless ProcessReferencesService.need_process?(@status, [], references)

Rails.cache.write("status_reference:#{@status.id}", true, expires_in: 10.minutes)
ProcessReferencesWorker.perform_async(@status.id, [], references)
ProcessReferencesService.perform_worker_async(@status, [], references)
end

def join_group!
Expand Down
5 changes: 1 addition & 4 deletions app/services/activitypub/process_status_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ def update_references!
quote = @json['quote'] || @json['quoteUrl'] || @json['quoteURL'] || @json['_misskey_quote']
references << quote if quote

return unless ProcessReferencesService.need_process?(@status, [], references)

Rails.cache.write("status_reference:#{@status.id}", true, expires_in: 10.minutes)
ProcessReferencesWorker.perform_async(@status.id, [], references)
ProcessReferencesService.perform_worker_async(@status, [], references)
end

def expected_type?
Expand Down
6 changes: 1 addition & 5 deletions app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,9 @@ def schedule_status!
def postprocess_status!
@account.user.update!(settings_attributes: { default_privacy: @options[:visibility] }) if @account.user&.setting_stay_privacy && !@status.reply? && %i(public public_unlisted login unlisted private).include?(@status.visibility.to_sym) && @status.visibility.to_s != @account.user&.setting_default_privacy && !@dtl

if ProcessReferencesService.need_process?(@status, @reference_ids, [])
Rails.cache.write("status_reference:#{@status.id}", true, expires_in: 10.minutes)
ProcessReferencesWorker.perform_async(@status.id, @reference_ids, [])
end

process_hashtags_service.call(@status)
Trends.tags.register(@status)
ProcessReferencesService.perform_worker_async(@status, @reference_ids, [])
LinkCrawlWorker.perform_async(@status.id)
DistributionWorker.perform_async(@status.id)
ActivityPub::DistributionWorker.perform_async(@status.id)
Expand Down
7 changes: 7 additions & 0 deletions app/services/process_references_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def self.need_process?(status, reference_parameters, urls)
reference_parameters.any? || (urls || []).any? || FormattingHelper.extract_status_plain_text(status).scan(REFURL_EXP).pluck(3).uniq.any?
end

def self.perform_worker_async(status, reference_parameters, urls)
return unless need_process?(status, reference_parameters, urls)

Rails.cache.write("status_reference:#{status.id}", true, expires_in: 10.minutes)
ProcessReferencesWorker.perform_async(status.id, reference_parameters, urls)
end

private

def references
Expand Down
5 changes: 1 addition & 4 deletions app/services/update_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ def reset_preview_card!
def update_references!
reference_ids = (@options[:status_reference_ids] || []).map(&:to_i).filter(&:positive?)

return unless ProcessReferencesService.need_process?(@status, reference_ids, [])

Rails.cache.write("status_reference:#{@status.id}", true, expires_in: 10.minutes)
ProcessReferencesWorker.perform_async(@status.id, reference_ids, [])
ProcessReferencesService.perform_worker_async(@status, reference_ids, [])
end

def update_metadata!
Expand Down

0 comments on commit a39b8cb

Please sign in to comment.