mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-17 18:52:30 -05:00
Moved the cache key to the utils module.
Renamed the dao method.
This commit is contained in:
@@ -8,9 +8,10 @@ from app import redis_store
|
||||
from app.dao.notifications_dao import (
|
||||
dao_get_template_usage,
|
||||
dao_get_last_template_usage)
|
||||
from app.dao.templates_dao import dao_get_templates_by_for_cache
|
||||
from app.dao.templates_dao import dao_get_templates_for_cache
|
||||
|
||||
from app.schemas import notification_with_template_schema
|
||||
from app.utils import cache_key_for_service_template_counter
|
||||
|
||||
template_statistics = Blueprint('template-statistics',
|
||||
__name__,
|
||||
@@ -61,12 +62,12 @@ def get_template_statistics_for_template_id(service_id, template_id):
|
||||
|
||||
|
||||
def get_template_statistics_for_7_days(limit_days, service_id):
|
||||
cache_key = "{}-template-counter-limit-7-days".format(service_id)
|
||||
cache_key = cache_key_for_service_template_counter(service_id)
|
||||
template_stats_by_id = redis_store.get_all_from_hash(cache_key)
|
||||
if not template_stats_by_id:
|
||||
stats = dao_get_template_usage(service_id, limit_days=limit_days)
|
||||
cache_values = dict([(x.template_id, x.count) for x in stats])
|
||||
redis_store.set_hash_and_expire(cache_key, cache_values, current_app.config.get('EXPIRE_CACHE_IN_SECONDS', 600))
|
||||
else:
|
||||
stats = dao_get_templates_by_for_cache(template_stats_by_id.items())
|
||||
stats = dao_get_templates_for_cache(template_stats_by_id.items())
|
||||
return stats
|
||||
|
||||
Reference in New Issue
Block a user