Skip to content

Commit

Permalink
feature: Adding extra_filters to warm_up_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bodley committed Aug 25, 2020
1 parent fe574fd commit 24bbafa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,12 +1431,16 @@ def warm_up_cache( # pylint: disable=too-many-locals,no-self-use
"""Warms up the cache for the slice or table.
Note for slices a force refresh occurs.
In terms of the `extra_filters` these can be obtained from records in the JSON
encoded `logs.json` column associated with the `explore_json` action.
"""
session = db.session()
slice_id = request.args.get("slice_id")
dashboard_id = request.args.get("dashboard_id")
table_name = request.args.get("table_name")
db_name = request.args.get("db_name")
extra_filters = request.args.get("extra_filters")

if not slice_id and not (table_name and db_name):
return json_error_response(
Expand Down Expand Up @@ -1482,8 +1486,10 @@ def warm_up_cache( # pylint: disable=too-many-locals,no-self-use
try:
form_data = get_form_data(slc.id, use_slice_data=True)[0]
if dashboard_id:
form_data["extra_filters"] = get_dashboard_extra_filters(
slc.id, dashboard_id
form_data["extra_filters"] = (
json.loads(extra_filters)
if extra_filters
else get_dashboard_extra_filters(slc.id, dashboard_id)
)

obj = get_viz(
Expand Down
11 changes: 11 additions & 0 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,17 @@ def test_warm_up_cache(self):
)
assert len(data) > 0

dashboard = self.get_dash_by_slug("births")

assert self.get_json_resp(
f"/superset/warm_up_cache?dashboard_id={dashboard.id}&slice_id={slc.id}"
) == [{"slice_id": slc.id, "viz_error": None, "viz_status": "success"}]

assert self.get_json_resp(
f"/superset/warm_up_cache?dashboard_id={dashboard.id}&slice_id={slc.id}&extra_filters="
+ quote(json.dumps([{"col": "name", "op": "in", "val": ["Jennifer"]}]))
) == [{"slice_id": slc.id, "viz_error": None, "viz_status": "success"}]

def test_shortner(self):
self.login(username="admin")
data = (
Expand Down

0 comments on commit 24bbafa

Please sign in to comment.