Add retention policy for cached content and media (#19232)
This commit is contained in:
parent
3e0999cd11
commit
5c9abdeff1
30 changed files with 559 additions and 135 deletions
33
spec/lib/vacuum/access_tokens_vacuum_spec.rb
Normal file
33
spec/lib/vacuum/access_tokens_vacuum_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::AccessTokensVacuum do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:revoked_access_token) { Fabricate(:access_token, revoked_at: 1.minute.ago) }
|
||||
let!(:active_access_token) { Fabricate(:access_token) }
|
||||
|
||||
let!(:revoked_access_grant) { Fabricate(:access_grant, revoked_at: 1.minute.ago) }
|
||||
let!(:active_access_grant) { Fabricate(:access_grant) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes revoked access tokens' do
|
||||
expect { revoked_access_token.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'deletes revoked access grants' do
|
||||
expect { revoked_access_grant.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'does not delete active access tokens' do
|
||||
expect { active_access_token.reload }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'does not delete active access grants' do
|
||||
expect { active_access_grant.reload }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
24
spec/lib/vacuum/backups_vacuum_spec.rb
Normal file
24
spec/lib/vacuum/backups_vacuum_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::BackupsVacuum do
|
||||
let(:retention_period) { 7.days }
|
||||
|
||||
subject { described_class.new(retention_period) }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:expired_backup) { Fabricate(:backup, created_at: (retention_period + 1.day).ago) }
|
||||
let!(:current_backup) { Fabricate(:backup) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes backups past the retention period' do
|
||||
expect { expired_backup.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'does not delete backups within the retention period' do
|
||||
expect { current_backup.reload }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
30
spec/lib/vacuum/feeds_vacuum_spec.rb
Normal file
30
spec/lib/vacuum/feeds_vacuum_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::FeedsVacuum do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:active_user) { Fabricate(:user, current_sign_in_at: 2.days.ago) }
|
||||
let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) }
|
||||
|
||||
before do
|
||||
redis.zadd(feed_key_for(inactive_user), 1, 1)
|
||||
redis.zadd(feed_key_for(active_user), 1, 1)
|
||||
redis.zadd(feed_key_for(inactive_user, 'reblogs'), 2, 2)
|
||||
redis.sadd(feed_key_for(inactive_user, 'reblogs:2'), 3)
|
||||
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'clears feeds of inactive users and lists' do
|
||||
expect(redis.zcard(feed_key_for(inactive_user))).to eq 0
|
||||
expect(redis.zcard(feed_key_for(active_user))).to eq 1
|
||||
expect(redis.exists?(feed_key_for(inactive_user, 'reblogs'))).to be false
|
||||
expect(redis.exists?(feed_key_for(inactive_user, 'reblogs:2'))).to be false
|
||||
end
|
||||
end
|
||||
|
||||
def feed_key_for(user, subtype = nil)
|
||||
FeedManager.instance.key(:home, user.account_id, subtype)
|
||||
end
|
||||
end
|
47
spec/lib/vacuum/media_attachments_vacuum_spec.rb
Normal file
47
spec/lib/vacuum/media_attachments_vacuum_spec.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::MediaAttachmentsVacuum do
|
||||
let(:retention_period) { 7.days }
|
||||
|
||||
subject { described_class.new(retention_period) }
|
||||
|
||||
let(:remote_status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com')) }
|
||||
let(:local_status) { Fabricate(:status) }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:old_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }
|
||||
let!(:old_local_media) { Fabricate(:media_attachment, status: local_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }
|
||||
let!(:new_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status) }
|
||||
let!(:new_local_media) { Fabricate(:media_attachment, status: local_status) }
|
||||
let!(:old_unattached_media) { Fabricate(:media_attachment, account_id: nil, created_at: 10.days.ago) }
|
||||
let!(:new_unattached_media) { Fabricate(:media_attachment, account_id: nil, created_at: 1.hour.ago) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes cache of remote media attachments past the retention period' do
|
||||
expect(old_remote_media.reload.file).to be_blank
|
||||
end
|
||||
|
||||
it 'does not touch local media attachments past the retention period' do
|
||||
expect(old_local_media.reload.file).to_not be_blank
|
||||
end
|
||||
|
||||
it 'does not delete cache of remote media attachments within the retention period' do
|
||||
expect(new_remote_media.reload.file).to_not be_blank
|
||||
end
|
||||
|
||||
it 'does not touch local media attachments within the retention period' do
|
||||
expect(new_local_media.reload.file).to_not be_blank
|
||||
end
|
||||
|
||||
it 'deletes unattached media attachments past TTL' do
|
||||
expect { old_unattached_media.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it 'does not delete unattached media attachments within TTL' do
|
||||
expect(new_unattached_media.reload).to be_persisted
|
||||
end
|
||||
end
|
||||
end
|
36
spec/lib/vacuum/preview_cards_vacuum_spec.rb
Normal file
36
spec/lib/vacuum/preview_cards_vacuum_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::PreviewCardsVacuum do
|
||||
let(:retention_period) { 7.days }
|
||||
|
||||
subject { described_class.new(retention_period) }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:orphaned_preview_card) { Fabricate(:preview_card, created_at: 2.days.ago) }
|
||||
let!(:old_preview_card) { Fabricate(:preview_card, updated_at: (retention_period + 1.day).ago) }
|
||||
let!(:new_preview_card) { Fabricate(:preview_card) }
|
||||
|
||||
before do
|
||||
old_preview_card.statuses << Fabricate(:status)
|
||||
new_preview_card.statuses << Fabricate(:status)
|
||||
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes cache of preview cards last updated before the retention period' do
|
||||
expect(old_preview_card.reload.image).to be_blank
|
||||
end
|
||||
|
||||
it 'does not delete cache of preview cards last updated within the retention period' do
|
||||
expect(new_preview_card.reload.image).to_not be_blank
|
||||
end
|
||||
|
||||
it 'does not delete attached preview cards' do
|
||||
expect(new_preview_card.reload).to be_persisted
|
||||
end
|
||||
|
||||
it 'deletes preview cards not attached to any status' do
|
||||
expect { orphaned_preview_card.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
end
|
36
spec/lib/vacuum/statuses_vacuum_spec.rb
Normal file
36
spec/lib/vacuum/statuses_vacuum_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::StatusesVacuum do
|
||||
let(:retention_period) { 7.days }
|
||||
|
||||
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
||||
|
||||
subject { described_class.new(retention_period) }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:remote_status_old) { Fabricate(:status, account: remote_account, created_at: (retention_period + 2.days).ago) }
|
||||
let!(:remote_status_recent) { Fabricate(:status, account: remote_account, created_at: (retention_period - 2.days).ago) }
|
||||
let!(:local_status_old) { Fabricate(:status, created_at: (retention_period + 2.days).ago) }
|
||||
let!(:local_status_recent) { Fabricate(:status, created_at: (retention_period - 2.days).ago) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes remote statuses past the retention period' do
|
||||
expect { remote_status_old.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'does not delete local statuses past the retention period' do
|
||||
expect { local_status_old.reload }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'does not delete remote statuses within the retention period' do
|
||||
expect { remote_status_recent.reload }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'does not delete local statuses within the retention period' do
|
||||
expect { local_status_recent.reload }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
22
spec/lib/vacuum/system_keys_vacuum_spec.rb
Normal file
22
spec/lib/vacuum/system_keys_vacuum_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::SystemKeysVacuum do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:expired_system_key) { Fabricate(:system_key, created_at: (SystemKey::ROTATION_PERIOD * 4).ago) }
|
||||
let!(:current_system_key) { Fabricate(:system_key) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes the expired key' do
|
||||
expect { expired_system_key.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'does not delete the current key' do
|
||||
expect { current_system_key.reload }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue