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

perf: speed up db migration for deprecating time_range_endpoints #19495

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Copy link
Member Author

Choose a reason for hiding this comment

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

Bycatch: unused imports

from sqlalchemy.ext.declarative import declarative_base

from superset import db
Expand All @@ -47,16 +46,17 @@ class Slice(Base):
def upgrade():
bind = op.get_bind()
session = db.Session(bind=bind)
for slc in session.query(Slice):
if slc.query_context:
try:
query_context = json.loads(slc.query_context)
except json.decoder.JSONDecodeError:
continue
queries = query_context.get("queries")
for query in queries:
query.get("extras", {}).pop("time_range_endpoints", None)
slc.queries = json.dumps(queries)
for slc in session.query(Slice).filter(
Slice.query_context.like("%time_range_endpoints%")
):
try:
query_context = json.loads(slc.query_context)
except json.decoder.JSONDecodeError:
continue
queries = query_context.get("queries")
for query in queries:
query.get("extras", {}).pop("time_range_endpoints", None)
slc.queries = json.dumps(queries)

session.commit()
session.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def upgrade():
bind = op.get_bind()
session = db.Session(bind=bind)

for slc in session.query(Slice):
params = json.loads(slc.params or "{}")
Copy link
Member Author

Choose a reason for hiding this comment

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

No need to fallback when we already filters to slices definitely have params.

for slc in session.query(Slice).filter(Slice.params.like("%time_range_endpoints%")):
params = json.loads(slc.params)
params.pop("time_range_endpoints", None)
slc.params = json.dumps(params)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
"""add_saved_query_foreign_key_to_tab_state
Copy link
Member Author

Choose a reason for hiding this comment

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

Bycatch: this makes superset db history prettier

Revision ID: c53bae8f08dd
Revises: bb38f40aa3ff
Create Date: 2021-12-15 15:05:21.845777
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
"""smaller_grid

Revision ID: e866bd2d4976
Revises: 21e88bc06c02
Create Date: 2018-02-13 08:07:40.766277
Expand Down