fix: dont retrieve stale target states#1099
Conversation
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe ChangesRelease Target Query Filtering
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 34 minutes and 15 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/api/src/routes/v1/workspaces/release-targets.ts`:
- Around line 286-297: The query building releaseTargets uses limit/offset
without deterministic ordering; update the db query that selects from
schema.releaseTargetDesiredRelease (the call that assigns releaseTargets) to add
an orderBy clause (e.g., order by schema.releaseTargetDesiredRelease.resourceId,
and optionally environmentId/deploymentId) so pagination is stable and rows
won’t shift between pages; ensure the orderBy is applied before limit/offset in
the query chain.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8cd99f79-4479-4073-86b0-1b12a633cdac
📒 Files selected for processing (1)
apps/api/src/routes/v1/workspaces/release-targets.ts
There was a problem hiding this comment.
Pull request overview
This PR updates the API endpoint that lists release-target states to avoid returning states for “stale” release targets by ensuring the requested (deployment, environment, resource) triple still exists in the computed selector results.
Changes:
- Filters
release_target_desired_releaserows by inner-joining againstcomputed_deployment_resourceandcomputed_environment_resource. - Narrows the selected columns for the paginated query to the release-target key fields (resourceId/environmentId/deploymentId).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .from(schema.releaseTargetDesiredRelease) | ||
| .innerJoin(schema.computedDeploymentResource, deploymentMatch) | ||
| .innerJoin(schema.computedEnvironmentResource, environmentMatch) | ||
| .where(filter) |
| const filter = and( | ||
| eq(schema.releaseTargetDesiredRelease.deploymentId, deploymentId), | ||
| eq(schema.releaseTargetDesiredRelease.environmentId, environmentId), | ||
| ); | ||
|
|
||
| const deploymentMatch = and( | ||
| eq( | ||
| schema.computedDeploymentResource.deploymentId, | ||
| schema.releaseTargetDesiredRelease.deploymentId, | ||
| ), | ||
| eq( | ||
| schema.computedDeploymentResource.resourceId, | ||
| schema.releaseTargetDesiredRelease.resourceId, | ||
| ), | ||
| ); | ||
|
|
||
| const environmentMatch = and( | ||
| eq( | ||
| schema.computedEnvironmentResource.environmentId, | ||
| schema.releaseTargetDesiredRelease.environmentId, | ||
| ), | ||
| eq( | ||
| schema.computedEnvironmentResource.resourceId, | ||
| schema.releaseTargetDesiredRelease.resourceId, | ||
| ), | ||
| ); | ||
|
|
||
| const [countResult] = await db | ||
| .select({ total: count() }) | ||
| .from(schema.releaseTargetDesiredRelease) | ||
| .innerJoin(schema.computedDeploymentResource, deploymentMatch) | ||
| .innerJoin(schema.computedEnvironmentResource, environmentMatch) | ||
| .where(filter); |
Summary by CodeRabbit