sadpandajoe commented on code in PR #43759:
URL: https://github.com/apache/superset/pull/43759#discussion_r3942064511


##########
superset/datasets/api.py:
##########
@@ -149,6 +157,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

Review Comment:
   This read-then-set counter is not atomic. Concurrent preview requests can 
all read the same value below the limit, each write the same incremented value, 
and all reach the warehouse probe, so a burst can bypass the query-load guard 
this endpoint relies on. Could this use an atomic cache increment/limit 
operation and cover concurrent requests?



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