ColtenOuO commented on code in PR #66222:
URL: https://github.com/apache/airflow/pull/66222#discussion_r3254252047


##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_pools.py:
##########
@@ -1133,6 +1134,35 @@ def test_update_mask_preserves_other_fields(self, 
test_client, session):
         assert updated_pool.description is None  # unchanged
         assert updated_pool.include_deferred is True  # unchanged
 
+    def test_bulk_delete_does_not_re_query_each_pool(self, test_client, 
session):
+        # Regression guard for the N+1 fix in 
BulkPoolService.handle_bulk_delete:
+        # the expected query count is independent of the number of deleted 
pools.
+        # The 4 queries are: (1) team-mapping auth check, (2) audit-log commit,
+        # (3) batched SELECT in categorize_pools, (4) commit that flushes the 
DELETEs.
+        # A regression that re-queries each pool inside the loop would add one
+        # SELECT per pool on top of these.
+        pool_names = [f"perf_pool_{i}" for i in range(5)]
+        session.add_all(Pool(pool=name, slots=1, include_deferred=False) for 
name in pool_names)
+        session.commit()
+
+        request_body = {
+            "actions": [
+                {
+                    "action": "delete",
+                    "entities": pool_names,
+                    "action_on_non_existence": "fail",
+                }
+            ]
+        }
+
+        with assert_queries_count(4):

Review Comment:
   Done! replaced the hardcoded 4 with a two-run comparison (5 pools vs 10 
pools, asserting equal query counts).



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

Reply via email to