From a8a803feef896416ad22796b5965d61c349dd1b6 Mon Sep 17 00:00:00 2001 From: Tet-9 Date: Sat, 30 May 2026 02:37:19 +0100 Subject: [PATCH] fix(miners): sort pull requests by state-relevant timestamp instead of created_at Both getPullRequests and getPullRequestsByRepo sorted all results by p.created_at DESC regardless of PR state. A PR opened 60 days ago but closed 2 days ago would appear below PRs opened more recently, making CLOSED results appear stale to validators. Fix both ORDER BY clauses to use COALESCE(p.merged_at, p.closed_at, p.created_at) DESC so each PR floats by the timestamp most relevant to its state. Also fixes the CLOSED filter to use closed_at >= since consistent with #139. Fixes #151 --- packages/das/src/api/miners/miners.service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/das/src/api/miners/miners.service.ts b/packages/das/src/api/miners/miners.service.ts index 2469d98..3b5b0d5 100644 --- a/packages/das/src/api/miners/miners.service.ts +++ b/packages/das/src/api/miners/miners.service.ts @@ -193,9 +193,9 @@ export class MinersService { AND ( (p.state = 'OPEN' AND p.created_at >= $2) OR (p.state = 'MERGED' AND p.merged_at >= $2) - OR (p.state = 'CLOSED' AND p.created_at >= $2) + OR (p.state = 'CLOSED' AND p.closed_at >= $2) ) - ORDER BY p.created_at DESC + ORDER BY COALESCE(p.merged_at, p.closed_at, p.created_at) DESC `, [githubId, since], ); @@ -242,9 +242,9 @@ export class MinersService { AND ( (p.state = 'OPEN' AND p.created_at >= w.since) OR (p.state = 'MERGED' AND p.merged_at >= w.since) - OR (p.state = 'CLOSED' AND p.created_at >= w.since) + OR (p.state = 'CLOSED' AND p.closed_at >= w.since) ) - ORDER BY p.created_at DESC + ORDER BY COALESCE(p.merged_at, p.closed_at, p.created_at) DESC `, [githubId, repoNames, sinceValues], );