alexandrusoare commented on code in PR #36109:
URL: https://github.com/apache/superset/pull/36109#discussion_r2533405743


##########
superset/commands/chart/warm_up_cache.py:
##########
@@ -45,54 +45,76 @@ def __init__(
         self._dashboard_id = dashboard_id
         self._extra_filters = extra_filters
 
+    def _get_dashboard_filters(self, chart_id: int) -> list[dict[str, Any]]:
+        """Retrieve dashboard filters from extra_filters or dashboard 
metadata."""
+        if not self._dashboard_id:
+            return []
+
+        if self._extra_filters:
+            return json.loads(self._extra_filters)
+
+        return get_dashboard_extra_filters(chart_id, self._dashboard_id)
+
+    def _warm_up_legacy_cache(
+        self, chart: Slice, form_data: dict[str, Any]
+    ) -> tuple[Any, Any]:
+        """Warm up cache for legacy visualizations."""
+        if not chart.datasource:
+            raise ChartInvalidError("Chart's datasource does not exist")
+
+        if self._dashboard_id:
+            form_data["extra_filters"] = self._get_dashboard_filters(chart.id)
+
+        g.form_data = form_data
+        payload = get_viz(
+            datasource_type=chart.datasource.type,
+            datasource_id=chart.datasource.id,
+            form_data=form_data,
+            force=True,
+        ).get_payload()
+        delattr(g, "form_data")
+
+        return payload["errors"] or None, payload["status"]
+
+    def _warm_up_non_legacy_cache(self, chart: Slice) -> tuple[Any, Any]:
+        """Warm up cache for non-legacy visualizations."""
+        query_context = chart.get_query_context()
+
+        if not query_context:
+            raise ChartInvalidError("Chart's query context does not exist")
+
+        # Apply dashboard filters if dashboard_id is provided
+        if dashboard_filters := self._get_dashboard_filters(chart.id):
+            for query in query_context.queries:
+                query.filter.extend(
+                    cast(list[QueryObjectFilterClause], dashboard_filters)
+                )
+
+        query_context.force = True
+        command = ChartDataCommand(query_context)
+        command.validate()
+        payload = command.run()
+
+        # Report the first error.
+        for query_result in cast(list[dict[str, Any]], payload["queries"]):
+            error = query_result.get("error")
+            status = query_result.get("status")
+            if error is not None:
+                return error, status
+
+        return None, None

Review Comment:
   I am not sure about this return of this tuple None, None



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to