@@ -1298,25 +1298,10 @@ pub async fn cancel_tasks_by_uuids(
12981298 // Query all matching tasks in a single query with permission checks
12991299 // Join with user_group to check Write permission
13001300 let builder = pool. db . get_database_backend ( ) ;
1301- let stmt = Query :: select ( )
1302- . columns ( [
1303- ( ActiveTasks :: Entity , ActiveTasks :: Column :: Id ) ,
1304- ( ActiveTasks :: Entity , ActiveTasks :: Column :: Uuid ) ,
1305- ( ActiveTasks :: Entity , ActiveTasks :: Column :: TaskId ) ,
1306- ( ActiveTasks :: Entity , ActiveTasks :: Column :: CreatorId ) ,
1307- ( ActiveTasks :: Entity , ActiveTasks :: Column :: GroupId ) ,
1308- ( ActiveTasks :: Entity , ActiveTasks :: Column :: Tags ) ,
1309- ( ActiveTasks :: Entity , ActiveTasks :: Column :: Labels ) ,
1310- ( ActiveTasks :: Entity , ActiveTasks :: Column :: CreatedAt ) ,
1311- ( ActiveTasks :: Entity , ActiveTasks :: Column :: UpdatedAt ) ,
1312- ( ActiveTasks :: Entity , ActiveTasks :: Column :: State ) ,
1313- ( ActiveTasks :: Entity , ActiveTasks :: Column :: AssignedWorker ) ,
1314- ( ActiveTasks :: Entity , ActiveTasks :: Column :: Timeout ) ,
1315- ( ActiveTasks :: Entity , ActiveTasks :: Column :: Priority ) ,
1316- ( ActiveTasks :: Entity , ActiveTasks :: Column :: Spec ) ,
1317- ( ActiveTasks :: Entity , ActiveTasks :: Column :: UpstreamTaskUuid ) ,
1318- ( ActiveTasks :: Entity , ActiveTasks :: Column :: DownstreamTaskUuid ) ,
1319- ] )
1301+
1302+ // Build a single-column subquery that selects only task IDs with permission checks.
1303+ let id_subquery = Query :: select ( )
1304+ . column ( ( ActiveTasks :: Entity , ActiveTasks :: Column :: Id ) )
13201305 . from ( ActiveTasks :: Entity )
13211306 // Join with user_group to verify user has Write permission on the group
13221307 . join (
@@ -1351,18 +1336,9 @@ pub async fn cancel_tasks_by_uuids(
13511336
13521337 // Build CTE for DELETE RETURNING + INSERT SELECT to avoid parameter limits
13531338 // Convert the SELECT statement into a subquery for the DELETE
1354- let task_id_subquery = stmt. clone ( ) ;
1355-
13561339 let delete_stmt = DeleteStatement :: new ( )
13571340 . from_table ( ActiveTasks :: Entity )
1358- . and_where (
1359- Expr :: col ( ActiveTasks :: Column :: Id ) . in_subquery (
1360- Query :: select ( )
1361- . column ( ActiveTasks :: Column :: Id )
1362- . from_subquery ( task_id_subquery, Alias :: new ( "matching_tasks" ) )
1363- . to_owned ( ) ,
1364- ) ,
1365- )
1341+ . and_where ( Expr :: col ( ActiveTasks :: Column :: Id ) . in_subquery ( id_subquery) )
13661342 . returning_all ( )
13671343 . to_owned ( ) ;
13681344
@@ -1435,8 +1411,7 @@ pub async fn cancel_tasks_by_uuids(
14351411 . to_owned ( ) ;
14361412
14371413 insert_stmt. select_from ( select_from_cte) . unwrap ( ) ;
1438- insert_stmt. returning_col ( ArchivedTasks :: Column :: Id ) ;
1439- insert_stmt. returning_col ( ArchivedTasks :: Column :: Uuid ) ;
1414+ insert_stmt. returning_all ( ) ;
14401415 let insert_with_cte = insert_stmt. with ( cte. into ( ) ) ;
14411416
14421417 let stmt = builder. build ( & insert_with_cte) ;
0 commit comments