mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
feat: saved queries with execution info (#11391)
* feat: add rows and last_run info to saved queries * feat: add rows to saved query * refactor and tests * lint * fix tests
This commit is contained in:
committed by
GitHub
parent
604a519d8b
commit
144b279aa2
@@ -23,6 +23,8 @@ import simplejson as json
|
||||
import sqlalchemy as sqla
|
||||
from flask import Markup
|
||||
from flask_appbuilder import Model
|
||||
from flask_appbuilder.models.decorators import renders
|
||||
from humanize import naturaltime
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
Column,
|
||||
@@ -181,6 +183,8 @@ class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin):
|
||||
foreign_keys=[db_id],
|
||||
backref=backref("saved_queries", cascade="all, delete-orphan"),
|
||||
)
|
||||
rows = Column(Integer, nullable=True)
|
||||
last_run = Column(DateTime, nullable=True)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return str(self.label)
|
||||
@@ -210,6 +214,18 @@ class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin):
|
||||
def sql_tables(self) -> List[Table]:
|
||||
return list(ParsedQuery(self.sql).tables)
|
||||
|
||||
@property
|
||||
def last_run_humanized(self) -> str:
|
||||
return naturaltime(datetime.now() - self.changed_on)
|
||||
|
||||
@property
|
||||
def _last_run_delta_humanized(self) -> str:
|
||||
return naturaltime(datetime.now() - self.changed_on)
|
||||
|
||||
@renders("changed_on")
|
||||
def last_run_delta_humanized(self) -> str:
|
||||
return self._last_run_delta_humanized
|
||||
|
||||
|
||||
class TabState(Model, AuditMixinNullable, ExtraJSONMixin):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user