Copilot commented on code in PR #40679:
URL: https://github.com/apache/superset/pull/40679#discussion_r3777625720


##########
superset/daos/log.py:
##########
@@ -120,19 +121,46 @@ def get_recent_activity(
                 .offset(page * page_size)
             )
 
+        logs = qry.all()
+
+        # Resolve the whole page's titles up front so the per-entry lookups
+        # below read from the request memo rather than calling the translation
+        # hook once per row.
+        translate_many(
+            (log.dashboard_title for log in logs if log.dashboard_id),
+            model_name="Dashboard",
+            field_name="dashboard_title",
+        )
+        translate_many(
+            (log.slice_name for log in logs if not log.dashboard_id and 
log.slice_id),
+            model_name="Slice",
+            field_name="slice_name",
+        )

Review Comment:
   `LogDAO.get_recent_activity()` prefetches translations via 
`translate_many(...)` unconditionally. When asset-translation is disabled, this 
still iterates the entire page of logs and builds intermediate collections for 
no benefit. Guard the prefetch behind `is_asset_translation_enabled()` so 
disabled deployments avoid the extra work.



##########
superset/models/dashboard.py:
##########
@@ -328,13 +344,25 @@ def data(self) -> dict[str, Any]:
         positions = self.position_json
         if positions:
             positions = json.loads(positions)
+        # Resolve every chart name in one shot; the per-slice 
``localized_name``
+        # lookups below then read from the request memo instead of hitting the
+        # translation hook once per chart.
+        translate_many(
+            (slc.slice_name for slc in self.slices),
+            model_name="Slice",
+            field_name="slice_name",
+        )

Review Comment:
   `Dashboard.data()` calls `translate_many(...)` unconditionally, which forces 
an extra iteration over `self.slices` and extra allocations even when 
asset-translation is disabled. Since the goal is zero overhead in 
single-language/flag-off deployments, guard the prefetch behind 
`is_asset_translation_enabled()` so the dashboard serialization only pays this 
cost when the feature is actually on.



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