0
0
Fork 0

Add retention policy for cached content and media (#19232)

This commit is contained in:
Eugen Rochko 2022-09-27 03:08:19 +02:00 committed by GitHub
parent 3e0999cd11
commit 5c9abdeff1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 559 additions and 135 deletions

View file

@ -1,17 +0,0 @@
# frozen_string_literal: true
class Scheduler::BackupCleanupScheduler
include Sidekiq::Worker
sidekiq_options retry: 0
def perform
old_backups.reorder(nil).find_each(&:destroy!)
end
private
def old_backups
Backup.where('created_at < ?', 7.days.ago)
end
end

View file

@ -1,13 +0,0 @@
# frozen_string_literal: true
class Scheduler::DoorkeeperCleanupScheduler
include Sidekiq::Worker
sidekiq_options retry: 0
def perform
Doorkeeper::AccessToken.where('revoked_at IS NOT NULL').where('revoked_at < NOW()').delete_all
Doorkeeper::AccessGrant.where('revoked_at IS NOT NULL').where('revoked_at < NOW()').delete_all
SystemKey.expired.delete_all
end
end

View file

@ -1,35 +0,0 @@
# frozen_string_literal: true
class Scheduler::FeedCleanupScheduler
include Sidekiq::Worker
include Redisable
sidekiq_options retry: 0
def perform
clean_home_feeds!
clean_list_feeds!
end
private
def clean_home_feeds!
feed_manager.clean_feeds!(:home, inactive_account_ids)
end
def clean_list_feeds!
feed_manager.clean_feeds!(:list, inactive_list_ids)
end
def inactive_account_ids
@inactive_account_ids ||= User.confirmed.inactive.pluck(:account_id)
end
def inactive_list_ids
List.where(account_id: inactive_account_ids).pluck(:id)
end
def feed_manager
FeedManager.instance
end
end

View file

@ -1,17 +0,0 @@
# frozen_string_literal: true
class Scheduler::MediaCleanupScheduler
include Sidekiq::Worker
sidekiq_options retry: 0
def perform
unattached_media.find_each(&:destroy)
end
private
def unattached_media
MediaAttachment.reorder(nil).unattached.where('created_at < ?', 1.day.ago)
end
end

View file

@ -0,0 +1,56 @@
# frozen_string_literal: true
class Scheduler::VacuumScheduler
include Sidekiq::Worker
sidekiq_options retry: 0
def perform
vacuum_operations.each do |operation|
operation.perform
rescue => e
Rails.logger.error("Error while running #{operation.class.name}: #{e}")
end
end
private
def vacuum_operations
[
statuses_vacuum,
media_attachments_vacuum,
preview_cards_vacuum,
backups_vacuum,
access_tokens_vacuum,
feeds_vacuum,
]
end
def statuses_vacuum
Vacuum::StatusesVacuum.new(content_retention_policy.content_cache_retention_period)
end
def media_attachments_vacuum
Vacuum::MediaAttachmentsVacuum.new(content_retention_policy.media_cache_retention_period)
end
def preview_cards_vacuum
Vacuum::PreviewCardsVacuum.new(content_retention_policy.media_cache_retention_period)
end
def backups_vacuum
Vacuum::BackupsVacuum.new(content_retention_policy.backups_retention_period)
end
def access_tokens_vacuum
Vacuum::AccessTokensVacuum.new
end
def feeds_vacuum
Vacuum::FeedsVacuum.new
end
def content_retention_policy
ContentRetentionPolicy.current
end
end