john-bodley commented on a change in pull request #9284: Reduce dashboard
bootstrap payload
URL:
https://github.com/apache/incubator-superset/pull/9284#discussion_r391868247
##########
File path: superset/connectors/base/models.py
##########
@@ -213,6 +235,77 @@ def data(self) -> Dict[str, Any]:
"select_star": self.select_star,
}
+ def data_for_slices(self, slices: List[Slice]) -> Dict[str, Any]:
+ """
+ The representation of the datasource containing only the required data
+ to render the provided slices.
+
+ Used to reduce the payload when loading a dashboard.
+ """
+ data = self.data
+ metric_names = set()
+ column_names = set()
+ for slc in slices:
+ form_data = slc.form_data
+
+ # pull out all required metrics from the form_data
+ for param in METRICS_FORM_DATA_PARAMS:
+ for metric in form_data.get(param) or []:
+ metric_names.add(utils.get_metric_name(metric))
+
+ # extra logic to handle adhoc metrics with column
references
+ if isinstance(metric, dict) and metric.get("column"):
Review comment:
Should we use the
[`is_adhoc_metric`](https://github.com/apache/incubator-superset/blob/7a91498cf1a9e56d4b3d7b3805076137525ea277/superset/utils/core.py#L944)
method here to improve readability and adhering to the DRY principle?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]