From e692e06b7fc3d13b4d274ad15a212af397dbf344 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Thu, 22 Mar 2018 16:18:22 +0000 Subject: [PATCH] add new template stat read pseudocode we can't use this new code until the new redis keys have been popualted for the last seven days --- app/template_statistics/rest.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/template_statistics/rest.py b/app/template_statistics/rest.py index 950b5ecd6..e6fbcb924 100644 --- a/app/template_statistics/rest.py +++ b/app/template_statistics/rest.py @@ -79,7 +79,22 @@ def get_template_statistics_for_7_days(limit_days, service_id): if cache_values: redis_store.set_hash_and_expire(cache_key, cache_values, - current_app.config.get('EXPIRE_CACHE_IN_SECONDS', 600)) + current_app.config['EXPIRE_CACHE_IN_SECONDS']) else: stats = dao_get_templates_for_cache(template_stats_by_id.items()) return stats + + # TODO: can only switch to this code when redis has been populated (either through time passing or a manual step) + # from collections import Counter + # from notifications_utils.redis_client import RedisException + # template_stats_by_id = Counter() + # for day in last_7_days: + # # "-template-usage-{YYYY-MM-DD}" + # key = cache_key_for_service_templates_used_per_day(service_id, limit_days) + # try: + # template_stats_by_id += Counter(redis_store.get_all_from_hash(key, raise_exception=True)) + # except RedisException: + # # TODO: ???? + # + # # TODO: streamline db query and avoid weird unions if possible. + # return dao_get_templates_for_cache(template_stats_by_id.items())