mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Some code clean up, removed print statements.
This commit is contained in:
@@ -59,29 +59,6 @@ def dao_get_template_versions(service_id, template_id):
|
||||
).all()
|
||||
|
||||
|
||||
# def dao_get_templates_by_for_cache(cache):
|
||||
# if not cache or len(cache) == 0:
|
||||
# return []
|
||||
|
||||
# # First create a subquery that is a union select of the cache values
|
||||
# # Then join templates to the subquery
|
||||
# cache_queries = [
|
||||
# db.session.query(sqlalchemy.sql.expression.bindparam("template_id" + str(i),
|
||||
# template_id).label('template_id'),
|
||||
# sqlalchemy.sql.expression.bindparam("count" + str(i), count).label('count'))
|
||||
# for i, (template_id, count) in enumerate(cache)]
|
||||
# cache_subq = cache_queries[0].union(*cache_queries[1:]).subquery()
|
||||
# query = db.session.query(Template.id.label('template_id'),
|
||||
# Template.template_type,
|
||||
# Template.name,
|
||||
# cache_subq.c.count.label('count')
|
||||
# ).join(cache_subq,
|
||||
# cast(Template.id, String) == cast(cache_subq.c.template_id, String)
|
||||
# ).order_by(Template.name)
|
||||
#
|
||||
# return query.all()
|
||||
|
||||
|
||||
def dao_get_templates_by_for_cache(cache):
|
||||
if not cache or len(cache) == 0:
|
||||
return []
|
||||
|
||||
@@ -35,12 +35,8 @@ def get_template_statistics_for_service_by_day(service_id):
|
||||
|
||||
if limit_days == 7:
|
||||
stats = get_template_statistics_for_7_days(limit_days, service_id)
|
||||
print(stats)
|
||||
# [(UUID('c2a331f8-e0b9-43de-9dd2-88300511a1d7'), 'Create with priority', 'sms', 1)]
|
||||
|
||||
else:
|
||||
stats = dao_get_template_usage(service_id, limit_days=limit_days)
|
||||
print(stats)
|
||||
|
||||
def serialize(data):
|
||||
return {
|
||||
@@ -68,12 +64,10 @@ def get_template_statistics_for_7_days(limit_days, service_id):
|
||||
cache_key = "{}-template-counter-limit-7-days".format(service_id)
|
||||
template_stats_by_id = redis_store.get_all_from_hash(cache_key)
|
||||
if not template_stats_by_id:
|
||||
print("populate cache")
|
||||
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))
|
||||
current_app.logger.info('use redis-client: {}'.format(cache_key))
|
||||
else:
|
||||
print("template_stats_by_id: {}".format(template_stats_by_id))
|
||||
stats = dao_get_templates_by_for_cache(template_stats_by_id.items())
|
||||
return stats
|
||||
|
||||
Reference in New Issue
Block a user