alex-poor commented on code in PR #40679:
URL: https://github.com/apache/superset/pull/40679#discussion_r3800068222
##########
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:
Fixed in e1a4944 — `Dashboard.data` now guards the prefetch behind
`is_asset_translation_enabled()`. You were right that `translate_many`
materialises and de-duplicates its input before consulting the feature flag, so
a flag-off deployment was still paying for the extra pass. Gated at the call
site rather than reordering inside `translate_many`, since that function is
contracted to return a mapping and can't avoid iterating; both core callers
only use it to prime the request memo, so skipping the call outright is what
actually reaches zero cost.
##########
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:
Fixed in e1a4944 — same gate applied to `LogDAO.get_recent_activity`, which
was the worse of the two: it made two passes over every page of activity with
the feature off.
--
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]