This is an automated email from the ASF dual-hosted git repository.
johnbodley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 502f4db feature: Adding extra_filters to warm_up_cache (#10675)
502f4db is described below
commit 502f4db6f9db1d1b9e039872ecac1c73c8fe0836
Author: John Bodley <[email protected]>
AuthorDate: Tue Aug 25 15:19:34 2020 -0700
feature: Adding extra_filters to warm_up_cache (#10675)
Co-authored-by: John Bodley <[email protected]>
---
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 d6ee690..49ffadd 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1431,12 +1431,16 @@ class Superset(BaseSupersetView): # pylint:
disable=too-many-public-methods
"""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 @@ class Superset(BaseSupersetView): # pylint:
disable=too-many-public-methods
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 d625860..88be98c 100644
--- a/tests/core_tests.py
+++ b/tests/core_tests.py
@@ -576,6 +576,17 @@ class TestCore(SupersetTestCase):
)
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 = (