Moved the cache key to the utils module.

Renamed the dao method.
This commit is contained in:
Rebecca Law
2017-02-14 14:22:52 +00:00
parent 1c6cfb9bc8
commit 53b7ad0961
7 changed files with 27 additions and 25 deletions

View File

@@ -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'),