From 24bbafa97bda82d4f4f0f2ad81db9603bf1a1b3e Mon Sep 17 00:00:00 2001 From: John Bodley Date: Tue, 25 Aug 2020 11:47:03 -0700 Subject: [PATCH] feature: Adding extra_filters to warm_up_cache --- superset/views/core.py | 10 ++++++++-- tests/core_tests.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/superset/views/core.py b/superset/views/core.py index d6ee6907fe7c7..49ffadd19f3c9 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -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( @@ -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( diff --git a/tests/core_tests.py b/tests/core_tests.py index d625860f2ff8a..88be98c3c1001 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -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 = (