fix(log): log cleanup sql query#4087
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@BugBot review |
PR SummaryMedium Risk Overview Also adjusts the retention predicate to compare against Reviewed by Cursor Bugbot for commit cafe8fe. Configure here. |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 5ef15c8. Configure here.
Greptile SummaryThis PR replaces a two-step memory-bound query (fetch all free-user IDs → pass as One incidental change deserves attention: the retention filter was silently switched from Confidence Score: 4/5Safe to merge after confirming the The core subquery fix is correct and directly addresses the production breakage. The only unresolved concern is the unannounced semantic change from apps/sim/app/api/logs/cleanup/route.ts — confirm the Important Files Changed
Sequence DiagramsequenceDiagram
participant Cron as Cron Job
participant Route as /api/logs/cleanup
participant DB as Database
Note over Route,DB: Before (broken — too many params)
Cron->>Route: GET request
Route->>DB: SELECT id FROM user (all free users)
DB-->>Route: [userId1, userId2, ..., userIdN]
Route->>DB: SELECT id FROM workspace WHERE billedAccountUserId IN ($1,$2,...,$N)
Note right of DB: Fails when N is large
DB-->>Route: Error: too many params
Note over Route,DB: After (fixed — subquery)
Cron->>Route: GET request
Route->>DB: SELECT logs WHERE workspaceId IN (SELECT workspace.id FROM workspace LEFT JOIN subscription WHERE subscription.id IS NULL) AND startedAt < retentionDate LIMIT 2000
DB-->>Route: [log batch]
Route->>DB: Archive + delete each log
Route-->>Cron: results, complete, batchLimitReached
Reviews (3): Last reviewed commit: "perf(log): use startedAt index for clean..." | Re-trigger Greptile |
waleedlatif1
left a comment
There was a problem hiding this comment.
also, let's see if there are any other efficiency issues with this query, in terms of it doing a full scan
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
Switch cleanup WHERE clause from createdAt to startedAt to leverage the existing composite index (workspaceId, startedAt), converting a full table scan to an index range scan. Also remove explanatory comment. Co-Authored-By: Claude Opus 4.6 <[email protected]>
e26497d to
cafe8fe
Compare
|
@greptile |
|
@cursor review |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit cafe8fe. Configure here.
* fix(log): log cleanup sql query * perf(log): use startedAt index for cleanup query filter Switch cleanup WHERE clause from createdAt to startedAt to leverage the existing composite index (workspaceId, startedAt), converting a full table scan to an index range scan. Also remove explanatory comment. Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Theodore Li <[email protected]> Co-authored-by: Waleed Latif <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]>
Summary
Our log cleanup was failing due to too many params passed:
This is because our old logic fetched every free user id into memory and then passed it to the second sql query. Changed this to use a subquery to fix free user log cleanup
Type of Change
Testing
How has this been tested? What should reviewers focus on?
Checklist
Screenshots/Videos