Skip to content

Commit

Permalink
No need to load user for recent queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
arikfr committed Jun 28, 2017
1 parent 470d2ad commit 92f93f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions redash/handlers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import sqlparse
from flask import jsonify, request
from funcy import distinct, take

from flask_login import login_required
from flask_restful import abort
from funcy import distinct, take
from sqlalchemy.orm.exc import StaleDataError

from redash import models, settings
from redash.handlers.base import (BaseResource, get_object_or_404,
org_scoped_rule, paginate, routes)
Expand All @@ -15,7 +16,6 @@
require_object_modify_permission,
require_permission, view_only)
from redash.utils import collect_parameters_from_request
from sqlalchemy.orm.exc import StaleDataError


@routes.route(org_scoped_rule('/api/queries/format'), methods=['POST'])
Expand Down Expand Up @@ -60,14 +60,14 @@ def get(self):

if settings.FEATURE_DUMB_RECENTS:
results = models.Query.by_user(self.current_user).order_by(models.Query.updated_at.desc()).limit(10)
queries = [q.to_dict(with_last_modified_by=False) for q in results]
queries = [q.to_dict(with_last_modified_by=False, with_user=False) for q in results]
else:
queries = models.Query.recent(self.current_user.group_ids, self.current_user.id)
recent = [d.to_dict(with_last_modified_by=False) for d in queries]
recent = [d.to_dict(with_last_modified_by=False, with_user=False) for d in queries]

global_recent = []
if len(recent) < 10:
global_recent = [d.to_dict(with_last_modified_by=False) for d in models.Query.recent(self.current_user.group_ids)]
global_recent = [d.to_dict(with_last_modified_by=False, with_user=False) for d in models.Query.recent(self.current_user.group_ids)]

queries = take(20, distinct(chain(recent, global_recent), key=lambda d: d['id']))

Expand Down
2 changes: 1 addition & 1 deletion redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ def search(cls, term, group_ids, include_drafts=False):

@classmethod
def recent(cls, group_ids, user_id=None, limit=20):
query = (cls.query.options(subqueryload(Query.user))
query = (cls.query
.filter(Event.created_at > (db.func.current_date() - 7))
.join(Event, Query.id == Event.object_id.cast(db.Integer))
.join(DataSourceGroup, Query.data_source_id == DataSourceGroup.data_source_id)
Expand Down

0 comments on commit 92f93f8

Please sign in to comment.