Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Address performance regression introduced in #11785 #20893

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic needed to be translated into a function that SQLAlchemy could understand as we're using this hybrid property as a filter.


@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