You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/07/13 05:02:00 UTC

[GitHub] [superset] john-bodley commented on a change in pull request #15648: perf: Refactor Dashboard.datasets_trimmed_for_slices et al.

john-bodley commented on a change in pull request #15648:
URL: https://github.com/apache/superset/pull/15648#discussion_r668382831



##########
File path: superset/models/dashboard.py
##########
@@ -246,12 +247,27 @@ def data(self) -> Dict[str, Any]:
         unless=lambda: not is_feature_enabled("DASHBOARD_CACHE"),
     )
     def datasets_trimmed_for_slices(self) -> List[Dict[str, Any]]:
-        datasource_slices = utils.indexed(self.slices, "datasource")
+
+        # Efficient manner of processing datasources associated with a dashboard. Rather
+        # than keying by the convenient `Slice.datasource` model (which results in a
+        # per slice database query), we lazily request datasource after deduping given
+        # that the same datasource could appear multiple times within a dashboard.
+        datasource_slices: Dict[
+            Tuple(Type["BaseDatasource"], int), Slice
+        ] = defaultdict(set)
+
+        for slc in self.slices:
+            datasource_slices[(slc.cls_model, slc.datasource_id)].add(slc)
+
         return [
             # Filter out unneeded fields from the datasource payload
             datasource.data_for_slices(slices)
-            for datasource, slices in datasource_slices.items()
-            if datasource
+            for (cls_model, datasource_id), slices in datasource_slices.items()
+            if (
+                datasource := db.session.query(cls_model)

Review comment:
       Loving the walrus. Sadly I later found out we needed to support Python 3.7.




-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org