-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
perf: Implement model specific lookups by id to improve performance #20974
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a695fc6
Implement model specific lookups by id to improve performance
bogdan-dbx 0ffe859
Address comments e.g. better variable names and test cleanup
bogdan-dbx fc63ff2
commit after cleanup
bogdan-dbx ab59aa4
even better name and test cleanup via rollback
bogdan-dbx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from typing import Iterator | ||
|
||
import pytest | ||
from sqlalchemy.orm.session import Session | ||
|
||
from superset.utils.core import DatasourceType | ||
|
||
|
||
@pytest.fixture | ||
def session_with_data(session: Session) -> Iterator[Session]: | ||
from superset.models.slice import Slice | ||
|
||
engine = session.get_bind() | ||
Slice.metadata.create_all(engine) # pylint: disable=no-member | ||
|
||
slice_obj = Slice( | ||
id=1, | ||
datasource_id=1, | ||
datasource_type=DatasourceType.TABLE, | ||
datasource_name="tmp_perm_table", | ||
slice_name="slice_name", | ||
) | ||
|
||
session.add(slice_obj) | ||
session.commit() | ||
yield session | ||
session.rollback() | ||
|
||
|
||
def test_slice_find_by_id_skip_base_filter(session_with_data: Session) -> None: | ||
from superset.charts.dao import ChartDAO | ||
from superset.models.slice import Slice | ||
|
||
result = ChartDAO.find_by_id(1, session=session_with_data, skip_base_filter=True) | ||
|
||
assert result | ||
assert 1 == result.id | ||
assert "slice_name" == result.slice_name | ||
assert isinstance(result, Slice) | ||
|
||
|
||
def test_datasource_find_by_id_skip_base_filter_not_found( | ||
session_with_data: Session, | ||
) -> None: | ||
from superset.charts.dao import ChartDAO | ||
|
||
result = ChartDAO.find_by_id( | ||
125326326, session=session_with_data, skip_base_filter=True | ||
) | ||
assert result is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from typing import Iterator | ||
|
||
import pytest | ||
from sqlalchemy.orm.session import Session | ||
|
||
|
||
@pytest.fixture | ||
def session_with_data(session: Session) -> Iterator[Session]: | ||
from superset.connectors.sqla.models import SqlaTable | ||
from superset.models.core import Database | ||
|
||
engine = session.get_bind() | ||
SqlaTable.metadata.create_all(engine) # pylint: disable=no-member | ||
|
||
db = Database(database_name="my_database", sqlalchemy_uri="sqlite://") | ||
sqla_table = SqlaTable( | ||
table_name="my_sqla_table", | ||
columns=[], | ||
metrics=[], | ||
database=db, | ||
) | ||
|
||
session.add(db) | ||
session.add(sqla_table) | ||
session.flush() | ||
yield session | ||
Comment on lines
+26
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same note about missing cleanup as previously. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
session.rollback() | ||
|
||
|
||
def test_datasource_find_by_id_skip_base_filter(session_with_data: Session) -> None: | ||
from superset.connectors.sqla.models import SqlaTable | ||
from superset.datasets.dao import DatasetDAO | ||
|
||
result = DatasetDAO.find_by_id( | ||
1, | ||
session=session_with_data, | ||
skip_base_filter=True, | ||
) | ||
|
||
assert result | ||
assert 1 == result.id | ||
assert "my_sqla_table" == result.table_name | ||
assert isinstance(result, SqlaTable) | ||
|
||
|
||
def test_datasource_find_by_id_skip_base_filter_not_found( | ||
session_with_data: Session, | ||
) -> None: | ||
from superset.datasets.dao import DatasetDAO | ||
|
||
result = DatasetDAO.find_by_id( | ||
125326326, | ||
session=session_with_data, | ||
skip_base_filter=True, | ||
) | ||
assert result is None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addresses mypy issue in