mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 09:28:27 -04:00
Make it easy to clear cache for all key formats
Having to submit the form for each choice separately slowed us down during an incident where Redis was unavailable and came back with stale data, which we had to clear manually. Note: we don't want to use the "flush" feature in case there are other keys in Redis, which may not be safe to remove.
This commit is contained in:
@@ -420,18 +420,27 @@ def clear_cache():
|
||||
])
|
||||
|
||||
form = ClearCacheForm()
|
||||
form.model_type.choices = [(key, key.replace('_', ' ').title()) for key in CACHE_KEYS]
|
||||
|
||||
form.model_type.choices = [
|
||||
(key, key.replace('_', ' ').title()) for key in CACHE_KEYS
|
||||
]
|
||||
|
||||
if form.validate_on_submit():
|
||||
group_key = form.model_type.data
|
||||
group = CACHE_KEYS[group_key]
|
||||
group_keys = form.model_type.data
|
||||
groups = map(CACHE_KEYS.get, group_keys)
|
||||
patterns = list(itertools.chain(*groups))
|
||||
|
||||
num_deleted = sum(
|
||||
redis_client.delete_cache_keys_by_pattern(pattern)
|
||||
for pattern in group
|
||||
for pattern in patterns
|
||||
)
|
||||
|
||||
msg = (
|
||||
f'Removed {num_deleted} objects '
|
||||
f'across {len(patterns)} key formats '
|
||||
f'for {", ".join(group_keys)}'
|
||||
)
|
||||
|
||||
msg = f'Removed {num_deleted} {group_key} objects across {len(group)} key formats'
|
||||
flash(msg, category='default')
|
||||
|
||||
return render_template(
|
||||
|
||||
Reference in New Issue
Block a user