Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Commit

Permalink
[fix] use filter_scopes in dashboard warmup strategy (apache#9235)
Browse files Browse the repository at this point in the history
* [fix] use filter_scopes in dashboard warmup strategy

* remove unnecessary comment
  • Loading branch information
Grace Guo committed Mar 6, 2020
1 parent 787833f commit 000a038
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
16 changes: 8 additions & 8 deletions superset/tasks/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ def get_form_data(chart_id, dashboard=None):
return form_data

json_metadata = json.loads(dashboard.json_metadata)

# do not apply filters if chart is immune to them
if chart_id in json_metadata.get("filter_immune_slices", []):
return form_data

default_filters = json.loads(json_metadata.get("default_filters", "null"))
if not default_filters:
return form_data

# are some of the fields in the chart immune to filters?
filter_immune_slice_fields = json_metadata.get("filter_immune_slice_fields", {})
immune_fields = filter_immune_slice_fields.get(str(chart_id), [])
# do not apply filters if chart is immune to them
immune_fields = []
filter_scopes = json_metadata.get("filter_scopes", {})
if filter_scopes:
for scopes in filter_scopes.values():
for (field, scope) in scopes.items():
if chart_id in scope.get("immune", []):
immune_fields.append(field)

extra_filters = []
for filters in default_filters.values():
Expand Down
18 changes: 15 additions & 3 deletions tests/strategy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def test_get_form_data_immune_slice(self):
dashboard = MagicMock()
dashboard.json_metadata = json.dumps(
{
"filter_immune_slices": [chart_id],
"filter_scopes": {
str(filter_box_id): {
"name": {"scope": ["ROOT_ID"], "immune": [chart_id]}
}
},
"default_filters": json.dumps(
{str(filter_box_id): {"name": ["Alice", "Bob"]}}
),
Expand Down Expand Up @@ -90,7 +94,11 @@ def test_get_form_data_immune_fields(self):
}
}
),
"filter_immune_slice_fields": {chart_id: ["__time_range"]},
"filter_scopes": {
str(filter_box_id): {
"__time_range": {"scope": ["ROOT_ID"], "immune": [chart_id]}
}
},
}
)
result = get_form_data(chart_id, dashboard)
Expand All @@ -109,7 +117,11 @@ def test_get_form_data_no_extra_filters(self):
"default_filters": json.dumps(
{str(filter_box_id): {"__time_range": "100 years ago : today"}}
),
"filter_immune_slice_fields": {chart_id: ["__time_range"]},
"filter_scopes": {
str(filter_box_id): {
"__time_range": {"scope": ["ROOT_ID"], "immune": [chart_id]}
}
},
}
)
result = get_form_data(chart_id, dashboard)
Expand Down

0 comments on commit 000a038

Please sign in to comment.