From 028f0f3cfc49c32e41662a0cdcdf9fe1cb0a45d7 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Mon, 15 Jun 2026 10:42:46 +0100 Subject: [PATCH] wip: maybe faster delete-unused-pipeline-statuses query Signed-off-by: oppiliappan --- appview/db/db.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/appview/db/db.go b/appview/db/db.go index 39689e42..7427ed83 100644 --- a/appview/db/db.go +++ b/appview/db/db.go @@ -2194,15 +2194,13 @@ func Make(ctx context.Context, dbPath string) (*DB, error) { orm.RunMigration(conn, logger, "delete-unused-pipeline-statuses", func(tx *sql.Tx) error { _, err := tx.Exec(` - delete from pipeline_statuses as p - where p.status = 'pending' - and exists ( - select 1 from pipeline_statuses as q - where q.pipeline_knot = p.pipeline_knot - and q.pipeline_rkey = p.pipeline_rkey - and q.workflow = p.workflow - and q.status = 'pending' - and q.created < p.created + delete from pipeline_statuses + where status = 'pending' + and id not in ( + select min(id) + from pipeline_statuses + where status = 'pending' + group by pipeline_knot, pipeline_rkey, workflow ); `) return err -- 2.51.2