mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 09:28:51 +00:00
Fix: queries API was doing N+1 queries in most cases
This commit is contained in:
parent
2ac64a7d08
commit
2db4b67505
@ -28,7 +28,7 @@ class QuerySearchResource(BaseResource):
|
||||
def get(self):
|
||||
term = request.args.get('q', '')
|
||||
|
||||
return [q.to_dict() for q in models.Query.search(term, self.current_user.groups)]
|
||||
return [q.to_dict(with_last_modified_by=False) for q in models.Query.search(term, self.current_user.groups)]
|
||||
|
||||
|
||||
class QueryRecentResource(BaseResource):
|
||||
@ -76,7 +76,7 @@ class QueryListResource(BaseResource):
|
||||
results = models.Query.all_queries(self.current_user.groups)
|
||||
page = request.args.get('page', 1, type=int)
|
||||
page_size = request.args.get('page_size', 25, type=int)
|
||||
return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True))
|
||||
return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
|
||||
|
||||
|
||||
class MyQueriesResource(BaseResource):
|
||||
@ -86,7 +86,7 @@ class MyQueriesResource(BaseResource):
|
||||
results = models.Query.by_user(self.current_user, drafts)
|
||||
page = request.args.get('page', 1, type=int)
|
||||
page_size = request.args.get('page_size', 25, type=int)
|
||||
return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True))
|
||||
return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
|
||||
|
||||
|
||||
class QueryResource(BaseResource):
|
||||
|
@ -700,7 +700,7 @@ class Query(ModelTimestampsMixin, BaseModel, BelongsToOrgMixin):
|
||||
.where(where) \
|
||||
.where(DataSourceGroup.group << groups)
|
||||
|
||||
return cls.select().where(cls.id << query_ids)
|
||||
return cls.select(Query, User).join(User).where(cls.id << query_ids)
|
||||
|
||||
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user