From 2ff7244c5563218b8f0613a1236f4e8f7e1635ff Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Wed, 18 Nov 2020 18:21:29 -0500 Subject: [PATCH] Add article cachebust backoff update script (#11472) * Add article cachebust backoff update script * ?i=i variant * Change values * Add select for optimization --- ...201118141822_gradual_article_cache_bust.rb | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/data_update_scripts/20201118141822_gradual_article_cache_bust.rb diff --git a/lib/data_update_scripts/20201118141822_gradual_article_cache_bust.rb b/lib/data_update_scripts/20201118141822_gradual_article_cache_bust.rb new file mode 100644 index 000000000..8c2d92300 --- /dev/null +++ b/lib/data_update_scripts/20201118141822_gradual_article_cache_bust.rb @@ -0,0 +1,24 @@ +module DataUpdateScripts + class GradualArticleCacheBust + def run + # This script is designed to bust the cache on article pages sufficient such that significant changes to + # CSS will not create meaningful visual regressions for most users. + # All articles have their caches naturally recycle once per day to finalize the transition. + + # This uses exponential backoff in order to bust the caches of more recent articles first, but not + # bust everything in too short a period, so that the edge cache can gradually re-heat without everything + # going cold at once. Articles with high "hotness score" (e.g. more recent) are the ones most in need of busting. + + # It only busts the "?i=i" variant of the path which is the "internal nav" version, aka the page when swapped + # with internal navigation, not the one landed on directly (which wouldn't have cache mismatches) + Article.published.order("hotness_score DESC").limit(1500).select(:path).each_with_index do |article, index| + n = index + 300 # + 300 gives the server time to boot up + BustCachePathWorker.set(queue: :high_priority).perform_in(n.seconds, "#{article.path}?i=i") + end + Article.published.order("hotness_score DESC").offset(1500).limit(3000).select(:path).each_with_index do |article, index| + n = (index * 3) + 450 + BustCachePathWorker.set(queue: :medium_priority).perform_in(n.seconds, "#{article.path}?i=i") + end + end + end +end