FIX: Always clear caches after committing the current transaction (#22550)

Instead of having to remember every time, just always wait until the
current transaction (if it exists) has committed before clearing any
DistributedCache.

The only exception to this is caches that aren't caching things from
postgres.

This means we have to do the test setup after setting the test
transaction, because doing the test setup involves clearing caches.

Reapplying this - it now doesn't use after_commit if skip_db is set
This commit is contained in:
Daniel Waterworth
2023-07-12 09:49:28 -05:00
committed by GitHub
parent 61aeb2da90
commit b7404373cf
6 changed files with 24 additions and 17 deletions

View File

@ -117,7 +117,7 @@ class Theme < ActiveRecord::Base
update_javascript_cache!
remove_from_cache!
DB.after_commit { ColorScheme.hex_cache.clear }
ColorScheme.hex_cache.clear
notify_theme_change(with_scheme: notify_with_scheme)
if theme_setting_requests_refresh
@ -358,7 +358,7 @@ class Theme < ActiveRecord::Base
end
def self.clear_cache!
DB.after_commit { @cache.clear }
@cache.clear
end
def self.targets
@ -529,12 +529,12 @@ class Theme < ActiveRecord::Base
def child_theme_ids=(theme_ids)
super(theme_ids)
DB.after_commit { Theme.clear_cache! }
Theme.clear_cache!
end
def parent_theme_ids=(theme_ids)
super(theme_ids)
DB.after_commit { Theme.clear_cache! }
Theme.clear_cache!
end
def add_relative_theme!(kind, theme)