mirror of
https://github.com/kikobar/mastodon.git
synced 2024-12-28 00:34:16 +00:00
Add auto-refresh of accounts we get new messages/edits of (#26510)
This commit is contained in:
parent
191d302b7f
commit
9ed0c91a37
|
@ -4,6 +4,8 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||||
include FormattingHelper
|
include FormattingHelper
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
|
@account.schedule_refresh_if_stale!
|
||||||
|
|
||||||
dereference_object!
|
dereference_object!
|
||||||
|
|
||||||
case @object['type']
|
case @object['type']
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
class ActivityPub::Activity::Update < ActivityPub::Activity
|
class ActivityPub::Activity::Update < ActivityPub::Activity
|
||||||
def perform
|
def perform
|
||||||
|
@account.schedule_refresh_if_stale!
|
||||||
|
|
||||||
dereference_object!
|
dereference_object!
|
||||||
|
|
||||||
if equals_or_includes_any?(@object['type'], %w(Application Group Organization Person Service))
|
if equals_or_includes_any?(@object['type'], %w(Application Group Organization Person Service))
|
||||||
|
|
|
@ -63,6 +63,8 @@ class Account < ApplicationRecord
|
||||||
trust_level
|
trust_level
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BACKGROUND_REFRESH_INTERVAL = 1.week.freeze
|
||||||
|
|
||||||
USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
|
USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
|
||||||
MENTION_RE = %r{(?<=^|[^/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}i
|
MENTION_RE = %r{(?<=^|[^/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}i
|
||||||
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
|
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
|
||||||
|
@ -209,6 +211,12 @@ class Account < ApplicationRecord
|
||||||
last_webfingered_at.nil? || last_webfingered_at <= 1.day.ago
|
last_webfingered_at.nil? || last_webfingered_at <= 1.day.ago
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def schedule_refresh_if_stale!
|
||||||
|
return unless last_webfingered_at.present? && last_webfingered_at <= BACKGROUND_REFRESH_INTERVAL.ago
|
||||||
|
|
||||||
|
AccountRefreshWorker.perform_in(rand(6.hours.to_i), id)
|
||||||
|
end
|
||||||
|
|
||||||
def refresh!
|
def refresh!
|
||||||
ResolveAccountService.new.call(acct) unless local?
|
ResolveAccountService.new.call(acct) unless local?
|
||||||
end
|
end
|
||||||
|
|
14
app/workers/account_refresh_worker.rb
Normal file
14
app/workers/account_refresh_worker.rb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AccountRefreshWorker
|
||||||
|
include Sidekiq::Worker
|
||||||
|
|
||||||
|
sidekiq_options queue: 'pull', retry: 3, dead: false, lock: :until_executed, lock_ttl: 1.day.to_i
|
||||||
|
|
||||||
|
def perform(account_id)
|
||||||
|
account = Account.find_by(id: account_id)
|
||||||
|
return if account.nil? || account.last_webfingered_at > Account::BACKGROUND_REFRESH_INTERVAL.ago
|
||||||
|
|
||||||
|
ResolveAccountService.new.call(account)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue