Constants for account refresh (#32420)
This commit is contained in:
parent
fae1de699c
commit
2f906ed55a
@ -65,6 +65,8 @@ class Account < ApplicationRecord
|
|||||||
)
|
)
|
||||||
|
|
||||||
BACKGROUND_REFRESH_INTERVAL = 1.week.freeze
|
BACKGROUND_REFRESH_INTERVAL = 1.week.freeze
|
||||||
|
REFRESH_DEADLINE = 6.hours
|
||||||
|
STALE_THRESHOLD = 1.day
|
||||||
DEFAULT_FIELDS_SIZE = 4
|
DEFAULT_FIELDS_SIZE = 4
|
||||||
INSTANCE_ACTOR_ID = -99
|
INSTANCE_ACTOR_ID = -99
|
||||||
|
|
||||||
@ -229,13 +231,13 @@ class Account < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def possibly_stale?
|
def possibly_stale?
|
||||||
last_webfingered_at.nil? || last_webfingered_at <= 1.day.ago
|
last_webfingered_at.nil? || last_webfingered_at <= STALE_THRESHOLD.ago
|
||||||
end
|
end
|
||||||
|
|
||||||
def schedule_refresh_if_stale!
|
def schedule_refresh_if_stale!
|
||||||
return unless last_webfingered_at.present? && last_webfingered_at <= BACKGROUND_REFRESH_INTERVAL.ago
|
return unless last_webfingered_at.present? && last_webfingered_at <= BACKGROUND_REFRESH_INTERVAL.ago
|
||||||
|
|
||||||
AccountRefreshWorker.perform_in(rand(6.hours.to_i), id)
|
AccountRefreshWorker.perform_in(rand(REFRESH_DEADLINE), id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh!
|
def refresh!
|
||||||
|
@ -208,16 +208,16 @@ RSpec.describe Account do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when last_webfingered_at is more than 24 hours before' do
|
context 'when last_webfingered_at is before the threshold' do
|
||||||
let(:last_webfingered_at) { 25.hours.ago }
|
let(:last_webfingered_at) { (described_class::STALE_THRESHOLD + 1.hour).ago }
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
expect(account.possibly_stale?).to be true
|
expect(account.possibly_stale?).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when last_webfingered_at is less than 24 hours before' do
|
context 'when last_webfingered_at is after the threshold' do
|
||||||
let(:last_webfingered_at) { 23.hours.ago }
|
let(:last_webfingered_at) { (described_class::STALE_THRESHOLD - 1.hour).ago }
|
||||||
|
|
||||||
it 'returns false' do
|
it 'returns false' do
|
||||||
expect(account.possibly_stale?).to be false
|
expect(account.possibly_stale?).to be false
|
||||||
|
Loading…
Reference in New Issue
Block a user