From d0723499a2d71fe1ed55d55d60cf7362351837c6 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 6 Sep 2024 13:51:55 +0200 Subject: [PATCH] [IMP] runbot_merge: stage by first ready This is an approximation under the assumption that stored computes update the `write_date`, and that there's not much else that will be computed on a batch. Eventually it might be a good idea for this to be a proper field, computed alongside the unblocking of the batch. Fixes #932 --- runbot_merge/models/stagings_create.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/runbot_merge/models/stagings_create.py b/runbot_merge/models/stagings_create.py index 55955a0a..75464045 100644 --- a/runbot_merge/models/stagings_create.py +++ b/runbot_merge/models/stagings_create.py @@ -195,11 +195,15 @@ def ready_batches(for_branch: Branch) -> Tuple[bool, Batch]: # staged through priority *and* through split. split_ids = for_branch.split_ids.batch_ids.ids env.cr.execute(""" - SELECT max(priority) - FROM runbot_merge_batch - WHERE blocked IS NULL AND target = %s AND NOT id = any(%s) + SELECT exists ( + SELECT FROM runbot_merge_batch + WHERE priority = 'alone' + AND blocked IS NULL + AND target = %s + AND NOT id = any(%s) + ) """, [for_branch.id, split_ids]) - alone = env.cr.fetchone()[0] == 'alone' + [alone] = env.cr.fetchone() return ( alone, @@ -208,7 +212,7 @@ def ready_batches(for_branch: Branch) -> Tuple[bool, Batch]: ('blocked', '=', False), ('priority', '=', 'alone') if alone else (1, '=', 1), ('id', 'not in', split_ids), - ], order="priority DESC, id ASC"), + ], order="priority DESC, write_date ASC, id ASC"), )