Skip to content

Commit

Permalink
Merge pull request #656 from rapidpro/fix-counts-cache-to-consider
Browse files Browse the repository at this point in the history
Generate cache keys for the configured sites only
  • Loading branch information
norkans7 authored Nov 11, 2020
2 parents e5064f1 + 862e1b0 commit daf31d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ureport/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions ureport/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit daf31d1

Please sign in to comment.