From debc16beda13d7b594670cb7ded091f2f83057cd Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Sat, 7 Sep 2024 08:20:24 +0530 Subject: [PATCH] chore: speed up agent history cleanup job --- job/cleanup.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/job/cleanup.go b/job/cleanup.go index e8d12462..a11a5906 100644 --- a/job/cleanup.go +++ b/job/cleanup.go @@ -44,14 +44,15 @@ func CleanupStaleAgentHistory(ctx context.Context, itemsToRetain int) (int, erro ) AS rn FROM job_history + WHERE + agent_id != ? ) DELETE FROM job_history WHERE id IN ( SELECT id FROM grouped_history WHERE - rn > ? AND - agent_id != ? + rn > ? LIMIT %d )`, batchSize) @@ -60,7 +61,7 @@ func CleanupStaleAgentHistory(ctx context.Context, itemsToRetain int) (int, erro for { // TODO (yashmehrotra): Use FastDB after debugging job failure //res := ctx.FastDB("jobs").Exec(query, itemsToRetain, uuid.Nil) - res := ctx.DB().Exec(query, itemsToRetain, uuid.Nil) + res := ctx.DB().Exec(query, uuid.Nil, itemsToRetain) if res.Error != nil { return deleted, db.ErrorDetails(res.Error) }