Skip to content

Commit

Permalink
perf(charts): improve performance on GET list (#9619)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaspar committed Apr 30, 2020
1 parent e95af7f commit 48ef619
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 8 additions & 5 deletions superset/charts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,22 @@ class ChartRestApi(BaseSupersetModelRestApi):
"slice_name",
"url",
"description",
"changed_by.username",
"changed_by_fk",
"created_by_fk",
"changed_by_name",
"changed_by_url",
"changed_by.first_name",
"changed_by.last_name",
"changed_on",
"datasource_id",
"datasource_type",
"datasource_name_text",
"datasource_url",
"table.default_endpoint",
"table.table_name",
"viz_type",
"params",
"cache_timeout",
"owners.id",
"owners.username",
"owners.first_name",
"owners.last_name",
]
order_columns = [
"slice_name",
Expand Down
15 changes: 14 additions & 1 deletion superset/models/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ class Slice(
perm = Column(String(1000))
schema_perm = Column(String(1000))
owners = relationship(security_manager.user_model, secondary=slice_user)
table = relationship(
"SqlaTable",
foreign_keys=[datasource_id],
primaryjoin="and_(Slice.datasource_id == SqlaTable.id, "
"Slice.datasource_type == 'table')",
remote_side="SqlaTable.id",
lazy="joined",
)

token = ""

export_fields = [
Expand Down Expand Up @@ -121,11 +130,15 @@ def datasource_link(self) -> Optional[Markup]:
@renders("datasource_url")
def datasource_url(self) -> Optional[str]:
# pylint: disable=no-member
if self.table:
return self.table.explore_url
datasource = self.datasource
return datasource.explore_url if datasource else None
return datasource.name if datasource else None

def datasource_name_text(self) -> Optional[str]:
# pylint: disable=no-member
if self.table:
return self.table.table_name
datasource = self.datasource
return datasource.name if datasource else None

Expand Down

0 comments on commit 48ef619

Please sign in to comment.