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
This commit is contained in:
Leo Hemsted
2018-03-22 16:18:22 +00:00
parent a0f74b35e1
commit e692e06b7f

View File

@@ -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:
# # "<SERVICE_ID>-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())