Skip to content

Commit

Permalink
perf: speed up db migration for deprecating time_range_endpoints (#19495
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ktmud authored Apr 1, 2022
1 parent 5fed10d commit 90dbe8d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
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
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 "{}")
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
Revision ID: c53bae8f08dd
Revises: bb38f40aa3ff
Create Date: 2021-12-15 15:05:21.845777
Expand Down
1 change: 1 addition & 0 deletions superset/migrations/versions/e866bd2d4976_smaller_grid.py
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

0 comments on commit 90dbe8d

Please sign in to comment.