mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Merge branch 'master' into stronger-2fa-security
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import (asc, desc)
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.sql.expression import bindparam
|
||||
|
||||
from app import db
|
||||
from app.models import (Template, TemplateHistory)
|
||||
@@ -56,3 +57,26 @@ def dao_get_template_versions(service_id, template_id):
|
||||
).order_by(
|
||||
desc(TemplateHistory.version)
|
||||
).all()
|
||||
|
||||
|
||||
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(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'),
|
||||
Template.template_type,
|
||||
Template.name,
|
||||
cache_subq.c.count.label('count')
|
||||
).join(cache_subq,
|
||||
Template.id == cache_subq.c.template_id
|
||||
).order_by(Template.name)
|
||||
|
||||
return query.all()
|
||||
|
||||
Reference in New Issue
Block a user