-
Notifications
You must be signed in to change notification settings - Fork 48
Implement Soft Limits for API Deployments Retrieval | Refactor deployments feature code #896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Warning Rate limit exceeded
⌛ 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. WalkthroughThe changes implement per-gateway deployment limiting with status-based ranking. A database index was added, the repository query was refactored to use CTEs for ranking deployments per gateway, and calling code was updated to propagate a configurable limit throughout the service and repository layers. One unused method was removed. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the GetDeploymentsWithState method to enforce a soft limit on the number of deployment records retrieved per gateway while ensuring that currently deployed/undeployed states are always prioritized over archived deployments.
Changes:
- Introduced window function-based ranking with
ROW_NUMBER()to limit results per gateway - Modified query to prioritize active deployments (DEPLOYED/UNDEPLOYED) over archived ones
- Optimized deployment existence check in gateway_internal.go to use
GetDeploymentStatusinstead ofGetDeploymentsWithState
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| platform-api/src/internal/repository/api.go | Refactored GetDeploymentsWithState with CTE-based window function query to implement soft limits and prioritization; removed unused CountDeploymentsByAPIAndGateway method |
| platform-api/src/internal/repository/interfaces.go | Added maxPerAPIGW parameter to GetDeploymentsWithState signature; removed CountDeploymentsByAPIAndGateway from interface |
| platform-api/src/internal/service/deployment.go | Updated GetDeploymentsWithState call to pass config value for maxPerAPIGW |
| platform-api/src/internal/service/gateway_internal.go | Changed from GetDeploymentsWithState to GetDeploymentStatus for more efficient deployment existence check |
| platform-api/src/internal/service/deployment_test.go | Updated mock signature to match new GetDeploymentsWithState interface |
| platform-api/src/internal/database/schema.postgres.sql | Added composite index idx_api_gw_created for optimizing the window function query |
Overview
This PR refactors the GetDeploymentsWithState method to enforce a soft limit of N records per Gateway while ensuring that current lifecycle states (DEPLOYED/UNDEPLOYED) are never truncated by the history limit.
Problem
Previously, a simple ORDER BY created_at could cause active deployments to be "pushed out" of the visible list if a high volume of new deployments were created (even if those new ones weren't actually deployed). Additionally, we lacked a per-gateway limit when querying across multiple gateways for a single API.
Changes
Weighted Ranking: Introduced a ROW_NUMBER() window function partitioned by gateway_uuid.
Prioritization Logic: Applied a CASE statement inside the ranking to ensure that any record existing in the api_deployment_status table (Priority 0) always receives rank_idx = 1.
Soft Limit Enforcement: Added a constraint to only return the top N records per gateway.
State Mapping: Improved the LEFT JOIN logic to correctly identify ARCHIVED deployments (those within the top N history that have no entry in the status table).
Filtering: Updated the query to support combined filters for gatewayID and status without breaking the ranking window.
Summary by CodeRabbit
Bug Fixes
Performance
Refactor