diff --git a/internal/inventory/batches.go b/internal/inventory/batches.go index 1d73228e..5e3c5e22 100644 --- a/internal/inventory/batches.go +++ b/internal/inventory/batches.go @@ -64,15 +64,13 @@ func (i *Inventory) LaterMergesOf(ctx context.Context, repository, branch string order by merged_at desc`, repository, branch, after) } -// KeptOnBranch says the controller keeps a merge of a repository's branch, and when it heard its first merge -// of any: a merge of a branch it keeps merges of, made since then, is the record's to answer, whatever a +// KeptOnBranch says the controller keeps a merge of a repository's branch, and when it heard the branch's first: a merge of a branch it keeps merges of, made since then, is the record's to answer, whatever a // module's last look says (novox/hq ADR 0276). func (i *Inventory) KeptOnBranch(ctx context.Context, repository, branch string) (bool, time.Time, error) { var first *time.Time var kept bool err := i.store.Pool().QueryRow(ctx, - `select (select min(heard_at) from batched_merge), - exists (select 1 from batched_merge where repository = lower($1) and branch = $2)`, + `select min(heard_at), count(*) > 0 from batched_merge where repository = lower($1) and branch = $2`, repository, branch).Scan(&first, &kept) if err != nil || first == nil { return false, time.Time{}, err