[refactor] use distinct in queries

parent 420feaca
......@@ -2,7 +2,7 @@
import datetime
import re
from sqlalchemy import between
from sqlalchemy import between, distinct
from sqlalchemy.sql.expression import and_
from sqlalchemy.sql.functions import min
from xivo_dao.alchemy import dbconnection
......@@ -51,6 +51,5 @@ def get_queue_names_in_range(start, end):
start = start.strftime(_STR_TIME_FMT)
end = end.strftime(_STR_TIME_FMT)
return [r.queuename for r in (_session().query(QueueLog.queuename)
.filter(between(QueueLog.time, start, end))
return [r[0] for r in (_session().query(distinct(QueueLog.queuename))
.filter(between(QueueLog.time, start, end)))]
# -*- coding: UTF-8 -*-
from sqlalchemy import distinct
from xivo_dao.alchemy.stat_queue import StatQueue
from xivo_dao.alchemy import dbconnection
......@@ -25,7 +25,7 @@ def id_from_name(queue_name):
def insert_if_missing(all_queues):
all_queues = set(all_queues)
old_queues = set([r.name for r in _session().query(StatQueue.name)])
old_queues = set(r[0] for r in _session().query(distinct(StatQueue.name)))
missing_queues = list(all_queues - old_queues)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment