DEV: Add a helper method to clear every possible theme cache (#17585)

Our theme system is very complex and it can take a while to figure out how to invalidate the various types of caches that are used throughout the theme system. So, having a single helper method that invalidates everything can be useful in emergency situations where there is no time to read through the code and figure out how to clear the various caches.

Internal ticket: t64732.
This commit is contained in:
Osama Sayegh
2022-07-22 09:46:52 +03:00
committed by GitHub
parent cf5e59928e
commit 306dca3a48
3 changed files with 136 additions and 3 deletions

View File

@ -1028,4 +1028,14 @@ module Discourse
def self.allow_dev_populate?
Rails.env.development? || ENV["ALLOW_DEV_POPULATE"] == "1"
end
# warning: this method is very expensive and shouldn't be called in places
# where performance matters. it's meant to be called manually (e.g. in the
# rails console) when dealing with an emergency that requires invalidating
# theme cache
def self.clear_all_theme_cache!
ThemeField.force_recompilation!
Theme.all.each(&:update_javascript_cache!)
Theme.expire_site_cache!
end
end