msyavuz commented on code in PR #44144:
URL: https://github.com/apache/superset/pull/44144#discussion_r4036668928
##########
superset/dashboards/api.py:
##########
@@ -198,6 +203,10 @@
logger = logging.getLogger(__name__)
+SCREENSHOT_API_LOCK_NAMESPACE = "dashboard_screenshot_api"
+SCREENSHOT_API_LOCK_WAIT_SECONDS = 1.0
Review Comment:
The producer holds the lock across `delay()` plus two cache writes, so with
a 1s wait a double-click or second tab during a slow broker publish gets a 503
instead of joining the generation.
##########
superset-frontend/src/dashboard/hooks/useDownloadScreenshot.ts:
##########
@@ -134,17 +168,28 @@ export const useDownloadScreenshot = (
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
})
- .catch(err => {
+ .catch(async err => {
Review Comment:
Non-404 GET failures (500, 403) resolve here without incrementing `retries`,
so the new cap never trips and polling runs until unmount.
##########
superset/dashboards/api.py:
##########
@@ -1965,44 +1984,241 @@ def cache_dashboard_screenshot(self, pk: int,
**kwargs: Any) -> WerkzeugResponse
dashboard_url = get_url_path("Superset.dashboard_permalink",
key=permalink_key)
screenshot_obj = DashboardScreenshot(dashboard_url, dashboard.digest)
- cache_key = screenshot_obj.get_cache_key(window_size, thumb_size,
permalink_key)
- image_url = get_url_path(
- "DashboardRestApi.screenshot", pk=dashboard.id, digest=cache_key
- )
- cache_payload = (
- screenshot_obj.get_from_cache_key(cache_key) or
ScreenshotCachePayload()
+ cache_scope = f"dashboard:{dashboard.id}"
+ request_cache_key = screenshot_obj.get_api_request_cache_key(
+ window_size,
+ thumb_size,
+ permalink_key,
+ cache_scope,
)
- def build_response(status_code: int) -> WerkzeugResponse:
+ def build_response(
+ status_code: int,
+ cache_key: str,
+ cache_payload: ScreenshotCachePayload,
+ ) -> WerkzeugResponse:
return self.response(
status_code,
cache_key=cache_key,
dashboard_url=dashboard_url,
- image_url=image_url,
+ image_url=get_url_path(
+ "DashboardRestApi.screenshot",
+ pk=dashboard.id,
+ digest=cache_key,
+ ),
+ task_timeout_seconds=(
Review Comment:
This and the stale in-progress check key off
`THUMBNAIL_COMPUTING_CACHE_TTL`, not the task's `soft_time_limit=300`; with a
TTL under 300 the UI gives up on a live worker and the next POST enqueues a
duplicate. `max(ttl, soft limit)`?
--
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]