Skip to content

fix(miners): sort pull requests by state-relevant timestamp instead of created_at#155

Open
Tet-9 wants to merge 1 commit into
entrius:testfrom
Tet-9:fix/151-closed-prs-sort-by-closed-at
Open

fix(miners): sort pull requests by state-relevant timestamp instead of created_at#155
Tet-9 wants to merge 1 commit into
entrius:testfrom
Tet-9:fix/151-closed-prs-sort-by-closed-at

Conversation

@Tet-9
Copy link
Copy Markdown
Contributor

@Tet-9 Tet-9 commented May 30, 2026

fix(miners): sort pull requests by state-relevant timestamp instead of created_at

Summary

getPullRequests and getPullRequestsByRepo in miners.service.ts sorted all pull request results by p.created_at DESC regardless of PR state. A PR opened 60 days ago but closed 2 days ago would appear near the bottom of results behind PRs opened more recently, making recently-resolved CLOSED PRs appear stale to validators.

Root Cause

Both query variants used a single fixed sort key for all states:

-- Before (incorrect)
ORDER BY p.created_at DESC

-- After (correct)
ORDER BY COALESCE(p.merged_at, p.closed_at, p.created_at) DESC

This is inconsistent with how the filter already distinguishes between states (merged_at for MERGED, closed_at for CLOSED after #139). The sort should reflect the same timestamp hierarchy.

Changes

Testing

Lint confirmed only pre-existing errors in cache.module.ts, unrelated to this change. Verified ORDER BY on issue query variants (lines 278, 321) were not affected.

Fixes #151

…f 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 entrius#139.

Fixes entrius#151
@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] miners API: CLOSED pull requests sorted by created_at instead of closed_at, causing recent closures to appear stale

1 participant