mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Moved the cache key to the utils module.
Renamed the dao method.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
|
||||
import sqlalchemy
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.sql.expression import bindparam
|
||||
|
||||
from app import db
|
||||
from app.models import (Template, TemplateHistory)
|
||||
@@ -59,16 +59,16 @@ def dao_get_template_versions(service_id, template_id):
|
||||
).all()
|
||||
|
||||
|
||||
def dao_get_templates_by_for_cache(cache):
|
||||
def dao_get_templates_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),
|
||||
uuid.UUID(template_id.decode())).label('template_id'),
|
||||
sqlalchemy.sql.expression.bindparam("count" + str(i), int(count.decode())).label('count'))
|
||||
db.session.query(bindparam("template_id" + str(i),
|
||||
uuid.UUID(template_id.decode())).label('template_id'),
|
||||
bindparam("count" + str(i), int(count.decode())).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'),
|
||||
|
||||
Reference in New Issue
Block a user