From 862e1b024bd0e2cc3114940dcbb99690f51027c2 Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Wed, 11 Nov 2020 18:33:33 +0200 Subject: [PATCH] Generate cache keys for the configured sites only --- ureport/utils/__init__.py | 11 +++++++++-- ureport/utils/tests.py | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ureport/utils/__init__.py b/ureport/utils/__init__.py index 3482538ac..a134b6bf0 100644 --- a/ureport/utils/__init__.py +++ b/ureport/utils/__init__.py @@ -293,9 +293,16 @@ def get_global_count(): return count_cached_value try: - old_site_reporter_counter_keys = cache.keys("org:*:reporters:old-site") + linked_sites = list(getattr(settings, "COUNTRY_FLAGS_SITES", [])) - cached_values = [cache.get(key) for key in old_site_reporter_counter_keys] + cached_values = [] + for site in linked_sites: + count_link = site.get("count_link", "") + if count_link: + key = "org:%s:reporters:%s" % (site.get("name").lower(), "old-site") + value = cache.get(key) + if value: + cached_values.append(value) # no old sites cache values, double check with a fetch if not cached_values: diff --git a/ureport/utils/tests.py b/ureport/utils/tests.py index 2f4d24925..24bca187b 100644 --- a/ureport/utils/tests.py +++ b/ureport/utils/tests.py @@ -549,6 +549,7 @@ def test_get_global_count(self): from django.core.cache import cache cache.delete(GLOBAL_COUNT_CACHE_KEY) + cache.set("org:ignored:reporters:old-site", {"time": 500, "results": dict(size=100)}, None) self.assertEqual(get_global_count(), 350) with patch("django.core.cache.cache.get") as cache_get_mock: