Skip to content

Commit

Permalink
[sql lab]revert apache#4833 (apache#7498)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace Guo authored May 24, 2019
1 parent e4f8444 commit 2014329
Showing 1 changed file with 8 additions and 39 deletions.
47 changes: 8 additions & 39 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import logging
import os
import re
import time
import traceback
from typing import List # noqa: F401
from urllib import parse
Expand All @@ -37,8 +36,7 @@
from flask_babel import lazy_gettext as _
import pandas as pd
import simplejson as json
import sqlalchemy as sqla
from sqlalchemy import and_, create_engine, MetaData, or_, select, update
from sqlalchemy import and_, create_engine, MetaData, or_, select
from sqlalchemy.engine.url import make_url
from sqlalchemy.exc import IntegrityError
from werkzeug.routing import BaseConverter
Expand Down Expand Up @@ -1846,7 +1844,7 @@ def recent_activity(self, user_id):
M.Slice.id == M.Log.slice_id,
)
.filter(
sqla.and_(
and_(
~M.Log.action.in_(('queries', 'shortner', 'sql_json')),
M.Log.user_id == user_id,
),
Expand Down Expand Up @@ -1916,7 +1914,7 @@ def fave_dashboards(self, user_id):
)
.join(
models.FavStar,
sqla.and_(
and_(
models.FavStar.user_id == int(user_id),
models.FavStar.class_name == 'Dashboard',
models.Dashboard.id == models.FavStar.obj_id,
Expand Down Expand Up @@ -1954,7 +1952,7 @@ def created_dashboards(self, user_id):
Dash,
)
.filter(
sqla.or_(
or_(
Dash.created_by_fk == user_id,
Dash.changed_by_fk == user_id,
),
Expand Down Expand Up @@ -1987,13 +1985,13 @@ def user_slices(self, user_id=None):
db.session.query(Slice,
FavStar.dttm).join(
models.FavStar,
sqla.and_(
and_(
models.FavStar.user_id == int(user_id),
models.FavStar.class_name == 'slice',
models.Slice.id == models.FavStar.obj_id,
),
isouter=True).filter(
sqla.or_(
or_(
Slice.created_by_fk == user_id,
Slice.changed_by_fk == user_id,
FavStar.user_id == user_id,
Expand Down Expand Up @@ -2024,7 +2022,7 @@ def created_slices(self, user_id=None):
qry = (
db.session.query(Slice)
.filter(
sqla.or_(
or_(
Slice.created_by_fk == user_id,
Slice.changed_by_fk == user_id,
),
Expand Down Expand Up @@ -2056,7 +2054,7 @@ def fave_slices(self, user_id=None):
)
.join(
models.FavStar,
sqla.and_(
and_(
models.FavStar.user_id == int(user_id),
models.FavStar.class_name == 'slice',
models.Slice.id == models.FavStar.obj_id,
Expand Down Expand Up @@ -2803,35 +2801,6 @@ def queries(self, last_updated_ms):
.all()
)
dict_queries = {q.client_id: q.to_dict() for q in sql_queries}

now = int(round(time.time() * 1000))

unfinished_states = [
QueryStatus.PENDING,
QueryStatus.RUNNING,
]

queries_to_timeout = [
client_id for client_id, query_dict in dict_queries.items()
if (
query_dict['state'] in unfinished_states and (
now - query_dict['startDttm'] >
config.get('SQLLAB_ASYNC_TIME_LIMIT_SEC') * 1000
)
)
]

if queries_to_timeout:
update(Query).where(
and_(
Query.user_id == g.user.get_id(),
Query.client_id in queries_to_timeout,
),
).values(state=QueryStatus.TIMED_OUT)

for client_id in queries_to_timeout:
dict_queries[client_id]['status'] = QueryStatus.TIMED_OUT

return json_success(
json.dumps(dict_queries, default=utils.json_int_dttm_ser))

Expand Down

0 comments on commit 2014329

Please sign in to comment.