EnxDev commented on code in PR #44144:
URL: https://github.com/apache/superset/pull/44144#discussion_r4013158060
##########
superset/utils/screenshots.py:
##########
@@ -532,3 +689,96 @@ def get_cache_key(
"permalink_key": permalink_key,
}
return hash_from_dict(args)
+
+ def get_api_request_cache_key(
+ self,
+ window_size: bool | WindowSize | None,
+ thumb_size: bool | WindowSize | None,
+ permalink_key: str,
+ scope: str,
+ ) -> str:
+ """Return the stable pointer key for one API screenshot request
state."""
+
+ return hash_from_dict(
+ {
+ "type": "dashboard_screenshot_api_request",
+ "version": 1,
+ "legacy_cache_key": self.get_cache_key(
+ window_size,
+ thumb_size,
+ permalink_key,
+ ),
+ "scope": scope,
+ }
+ )
+
+ @staticmethod
+ def get_next_api_generation_cache_key(
+ request_cache_key: str,
+ previous_cache_key: str | None,
+ ) -> str:
+ """Return a deterministic successor so racing producers coalesce."""
+
+ return hash_from_dict(
+ {
+ "type": "dashboard_screenshot_api_generation",
+ "request_cache_key": request_cache_key,
+ "previous_cache_key": previous_cache_key,
Review Comment:
Could we give a new generation a unique key even when the request pointer
has expired? The pointer gets its cache TTL when the API enqueues, while the
image gets a fresh TTL when the worker finishes, so there's a normal window
where the pointer is gone but the old image is still downloadable. In that
window, `previous_cache_key` becomes `None` again and this recreates the first
generation's key; the API then overwrites that valid artifact with `Pending`.
I reproduced this with the cache helpers and a controlled SimpleCache clock:
publish at t=0 with a 100s TTL, store the completed image at t=50, then request
again at t=101. The replacement key equals the old key and its payload changes
from `Updated` to `Pending`, so the previous download URL loses its image
before its own expiry. A fresh generation identifier allocated under the
producer lock would preserve the old URL. Could we add an expiry regression
test alongside that change?
--
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]