mirror of
https://github.com/valitydev/redash.git
synced 2024-11-08 18:03:54 +00:00
No need to load user for recent queries.
This commit is contained in:
parent
470d2ad359
commit
92f93f8ff6
@ -2,10 +2,11 @@ from itertools import chain
|
||||
|
||||
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)
|
||||
@ -15,7 +16,6 @@ from redash.permissions import (can_modify, not_view_only, require_access,
|
||||
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'])
|
||||
@ -60,14 +60,14 @@ class QueryRecentResource(BaseResource):
|
||||
|
||||
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']))
|
||||
|
||||
|
@ -915,7 +915,7 @@ class Query(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model):
|
||||
|
||||
@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)
|
||||
|
Loading…
Reference in New Issue
Block a user