sadpandajoe commented on code in PR #43759:
URL: https://github.com/apache/superset/pull/43759#discussion_r4155609394
##########
superset/datasets/api.py:
##########
@@ -153,6 +161,31 @@
)
+def _consume_preview_rate_limit(dataset_id: int) -> bool:
+ """
+ Fixed-window per-user, per-dataset throttle on the preview endpoint.
+
+ Debouncing on the client is a courtesy, not a guard: a held keydown, or a
+ handful of owners with the editor open, becomes sustained load on a
+ production cluster. Returns False once the window's budget is spent.
+ """
+ limit = app.config.get("PARTITION_TRANSFORM_PREVIEW_RATE_LIMIT", 30)
+ if not limit:
+ return True
+
+ user_id = get_user_id() or 0
+ key = f"partition_mapping_preview:{user_id}:{dataset_id}"
+ try:
+ used = cache_manager.cache.get(key) or 0
+ if used >= limit:
+ return False
+ cache_manager.cache.set(key, used + 1, timeout=60)
Review Comment:
Agreed—the current `inc()` still resets the expiry on SimpleCache and other
read-modify-write backends, using the default cache timeout rather than 60
seconds. With the one-day default, retries after the budget is spent keep
renewing a day-long lockout; could the fixed-window behavior be enforced for
supported backends or the Redis-only requirement be explicit?
--
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]