Fix: Queries#all_queries was sometimes returning wrong number of queries.

This commit is contained in:
Arik Fraimovich 2017-09-27 18:17:57 +03:00
parent 18d9b2eec9
commit ada8a1255b

View File

@ -848,13 +848,16 @@ class Query(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model):
@classmethod
def all_queries(cls, group_ids, user_id=None, drafts=False):
query_ids = (db.session.query(distinct(cls.id))
.join(DataSourceGroup, Query.data_source_id == DataSourceGroup.data_source_id)
.filter(Query.is_archived == False)
.filter(DataSourceGroup.group_id.in_(group_ids)))
q = (cls.query
.options(joinedload(Query.user),
joinedload(Query.latest_query_data).load_only('runtime', 'retrieved_at'))
.join(DataSourceGroup, Query.data_source_id == DataSourceGroup.data_source_id)
.filter(Query.is_archived == False)
.filter(DataSourceGroup.group_id.in_(group_ids))
.order_by(Query.created_at.desc()))
.options(joinedload(Query.user),
joinedload(Query.latest_query_data).load_only('runtime', 'retrieved_at'))
.filter(cls.id.in_(query_ids))
.order_by(Query.created_at.desc()))
if not drafts:
q = q.filter(or_(Query.is_draft == False, Query.user_id == user_id))