Skip to content

Commit

Permalink
fix: Address performance regression introduced in #11785 (#20893)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored Jul 29, 2022
1 parent 3f124d9 commit 50d2e5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ include-naming-hint=no

# List of decorators that produce properties, such as abc.abstractproperty. Add
# to this list to register other decorators that produce valid properties.
property-classes=abc.abstractproperty
property-classes=
abc.abstractproperty,
sqlalchemy.ext.hybrid.hybrid_property

# Regular expression matching correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}$
Expand Down
11 changes: 5 additions & 6 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
update,
)
from sqlalchemy.engine.base import Connection
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import backref, Query, relationship, RelationshipProperty, Session
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.orm.mapper import Mapper
Expand Down Expand Up @@ -741,7 +742,7 @@ class SqlaTable(Model, BaseDatasource): # pylint: disable=too-many-public-metho
"MAX": sa.func.MAX,
}

def __repr__(self) -> str:
def __repr__(self) -> str: # pylint: disable=invalid-repr-returned
return self.name

@staticmethod
Expand Down Expand Up @@ -835,11 +836,9 @@ def get_perm(self) -> str:
raise DatasetInvalidPermissionEvaluationException()
return f"[{self.database}].[{self.table_name}](id:{self.id})"

@property
def name(self) -> str:
if not self.schema:
return self.table_name
return "{}.{}".format(self.schema, self.table_name)
@hybrid_property
def name(self) -> str: # pylint: disable=invalid-overridden-method
return self.schema + "." + self.table_name if self.schema else self.table_name

@property
def full_name(self) -> str:
Expand Down
15 changes: 11 additions & 4 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,16 @@ def is_match(src: str, target: utils.DatasourceName) -> bool:
max_tables = max_items * len(tables) // total_items
max_views = max_items * len(views) // total_items

dataset_tables = {table.name: table for table in database.tables}
extra_dict_by_name = {
table.name: table.extra_dict
for table in (
db.session.query(SqlaTable).filter(
SqlaTable.name.in_( # # pylint: disable=no-member
f"{table.schema}.{table.table}" for table in tables
)
)
).all()
}

table_options = [
{
Expand All @@ -1216,9 +1225,7 @@ def is_match(src: str, target: utils.DatasourceName) -> bool:
"label": get_datasource_label(tn),
"title": get_datasource_label(tn),
"type": "table",
"extra": dataset_tables[f"{tn.schema}.{tn.table}"].extra_dict
if (f"{tn.schema}.{tn.table}" in dataset_tables)
else None,
"extra": extra_dict_by_name.get(f"{tn.schema}.{tn.table}", None),
}
for tn in tables[:max_tables]
]
Expand Down

0 comments on commit 50d2e5a

Please sign in to comment.