PERF: Add scheduled job to delete old stylesheet cache rows (#13747)

This commit is contained in:
Penar Musaraj
2021-07-16 10:58:01 -04:00
committed by GitHub
parent 810892139b
commit 361c8be547
3 changed files with 37 additions and 1 deletions

View File

@ -4,7 +4,7 @@ require 'rails_helper'
describe StylesheetCache do
describe "add" do
describe ".add" do
it "correctly cycles once MAX_TO_KEEP is hit" do
StylesheetCache.destroy_all
@ -37,6 +37,26 @@ describe StylesheetCache do
expect(StylesheetCache.order(:id).pluck(:target)).to eq(["desktop", "desktop", "mobile", "mobile"])
end
end
describe ".clean_up" do
it "removes items older than threshold" do
StylesheetCache.destroy_all
StylesheetCache.add("a", "b", "c", "map")
StylesheetCache.add("d", "e", "f", "map")
above_threshold = StylesheetCache::CLEANUP_AFTER_DAYS - 1
StylesheetCache.first.update!(created_at: above_threshold.days.ago)
StylesheetCache.clean_up
expect(StylesheetCache.all.size).to eq(2)
below_threshold = StylesheetCache::CLEANUP_AFTER_DAYS + 1
StylesheetCache.first.update!(created_at: below_threshold.days.ago)
StylesheetCache.clean_up
expect(StylesheetCache.all.size).to eq(1)
end
end
end