Add periodic removal of older thumbnails for preview cards (#11304)
This commit is contained in:
		
							parent
							
								
									c4a05eaa87
								
							
						
					
					
						commit
						ac853dca51
					
				
					 3 changed files with 43 additions and 0 deletions
				
			
		
							
								
								
									
										18
									
								
								app/workers/maintenance/uncache_preview_worker.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								app/workers/maintenance/uncache_preview_worker.rb
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
class Maintenance::UncachePreviewWorker
 | 
			
		||||
  include Sidekiq::Worker
 | 
			
		||||
 | 
			
		||||
  sidekiq_options queue: 'pull'
 | 
			
		||||
 | 
			
		||||
  def perform(preview_card_id)
 | 
			
		||||
    preview_card = PreviewCard.find(preview_card_id)
 | 
			
		||||
 | 
			
		||||
    return if preview_card.image.blank?
 | 
			
		||||
 | 
			
		||||
    preview_card.image.destroy
 | 
			
		||||
    preview_card.save
 | 
			
		||||
  rescue ActiveRecord::RecordNotFound
 | 
			
		||||
    true
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										22
									
								
								app/workers/scheduler/preview_cards_cleanup_scheduler.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								app/workers/scheduler/preview_cards_cleanup_scheduler.rb
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
class Scheduler::PreviewCardsCleanupScheduler
 | 
			
		||||
  include Sidekiq::Worker
 | 
			
		||||
 | 
			
		||||
  sidekiq_options unique: :until_executed, retry: 0
 | 
			
		||||
 | 
			
		||||
  def perform
 | 
			
		||||
    Maintenance::UncachePreviewWorker.push_bulk(recent_link_preview_cards.pluck(:id))
 | 
			
		||||
    Maintenance::UncachePreviewWorker.push_bulk(older_preview_cards.pluck(:id))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def recent_link_preview_cards
 | 
			
		||||
    PreviewCard.where(type: :link).where('updated_at < ?', 1.month.ago)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def older_preview_cards
 | 
			
		||||
    PreviewCard.where('updated_at < ?', 6.months.ago)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -27,6 +27,9 @@
 | 
			
		|||
  ip_cleanup_scheduler:
 | 
			
		||||
    cron: '<%= Random.rand(0..59) %> <%= Random.rand(3..5) %> * * *'
 | 
			
		||||
    class: Scheduler::IpCleanupScheduler
 | 
			
		||||
  preview_cards_cleanup_scheduler:
 | 
			
		||||
    cron: '<%= Random.rand(0..59) %> <%= Random.rand(3..5) %> * * *'
 | 
			
		||||
    class: Scheduler::PreviewCardsCleanupScheduler
 | 
			
		||||
  email_scheduler:
 | 
			
		||||
    cron: '0 10 * * 2'
 | 
			
		||||
    class: Scheduler::EmailScheduler
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue