fix(statistics): org dashboard bandwidth truncated by PostgREST max_rows - #2738
Conversation
📝 WalkthroughWalkthroughBandwidth aggregation is refactored into a typed helper, the admin dashboard adds a bandwidth trend chart, scale-focused bandwidth tests are introduced, legacy download tracking is covered, and queue cleanup now handles missing metadata tables. ChangesBandwidth reporting
Queue cleanup migration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant AdminDashboard
participant loadDashboardData
participant bandwidth_trend
AdminDashboard->>loadDashboardData: load dashboard datasets
loadDashboardData->>bandwidth_trend: fetch bandwidth trend
bandwidth_trend-->>loadDashboardData: return trend data
loadDashboardData-->>AdminDashboard: render bandwidth chart
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_d5a14a02-843c-45fb-b50d-ec9c8d012d6c) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Cursor Bugbot was skipped (usage limit reached), so automated review did not complete successfully. Human review is needed for the cloudflare.ts refactor and migration guard; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver External
ede0643 to
daec587
Compare
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_c903480d-6661-4eb8-a688-3a1da119bf7d) |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_00234991-8280-48c9-a9aa-baed2948a43e) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot did not complete successfully (check skipped due to usage limit), so the automated review signal is missing. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver
There was a problem hiding this comment.
Stale comment
Risk: medium. Cursor Bugbot was skipped (usage limit reached), so automated review did not complete successfully. Human review is still needed for the cloudflare.ts and migration changes; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver External
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/bandwidth-report-scale.unit.test.ts`:
- Around line 104-106: Strengthen the negative SQL assertion in the test around
fnSql so it rejects a standalone FROM public.apps a table reference regardless
of following WHERE, JOIN, or other SQL tokens. Keep the positive INNER JOIN
public.apps a ON ... assertion, but remove the ineffective semicolon-specific
pattern.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: eef26a81-fab0-44a4-a8b3-ba1acab8d6e2
📒 Files selected for processing (7)
messages/en.jsonsrc/pages/admin/dashboard/updates.vuesupabase/functions/_backend/utils/cloudflare.tssupabase/migrations/20260723113511_cleanup_queue_skip_missing_tables.sqltests/bandwidth-report-scale.test.tstests/bandwidth-report-scale.unit.test.tstests/files-bandwidth.unit.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
Cap-go/capacitor-updater(manual)
Org all-apps dashboards call get_app_metrics for every app × day and were silently truncated at 1000 rows, so bandwidth for later app_ids disappeared while single-app stats still worked. Page the RPC like storage_byte_hours and index metrics by date. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
daec587 to
4914fc3
Compare
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_4712b087-88f6-4b7b-af3e-479fd9ef4996) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot did not complete successfully (check skipped due to usage limit), so the automated review signal is missing. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver
There was a problem hiding this comment.
Stale comment
Risk: low. Not approving: Cursor Bugbot did not complete successfully (check skipped due to usage limit), so the automated review signal is missing. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver External
Satisfy backend typecheck for the PostgREST range pagination chain. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
getDaysBetweenDates excludes the end date from graph indexes, so end-day bandwidth never appears in /statistics aggregates. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
…ixture Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
|
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_394c50a4-fb12-49b5-9aa5-88c532f602bd) |
There was a problem hiding this comment.
Risk: low. Not approving: Cursor Bugbot did not complete successfully (check skipped due to usage limit), so the automated review signal is missing. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver External
There was a problem hiding this comment.
1 issue found across 3 files
Confidence score: 4/5
- In
tests/org-statistics-bandwidth-pagination.test.ts, mutating the sharedUSER_IDfixture can leak random organization membership into parallel tests, creating order-dependent failures and flaky CI runs rather than a product bug — switch this test to a dedicated seeded user (or fully isolated fixture) to remove shared-state coupling.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/org-statistics-bandwidth-pagination.test.ts">
<violation number="1" location="tests/org-statistics-bandwidth-pagination.test.ts:64">
P2: This test mutates the shared `USER_ID` fixture's organization membership, so parallel tests using the same user can observe the random org and become order-dependent. A dedicated seeded test user (or an isolated fixture identity) would keep the pagination regression data independent from other backend tests.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| beforeAll(async () => { | ||
| // created_by bootstraps org_users + org_super_admin role_bindings | ||
| await getSupabaseClient().from('orgs').insert({ | ||
| created_by: USER_ID, |
There was a problem hiding this comment.
P2: This test mutates the shared USER_ID fixture's organization membership, so parallel tests using the same user can observe the random org and become order-dependent. A dedicated seeded test user (or an isolated fixture identity) would keep the pagination regression data independent from other backend tests.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/org-statistics-bandwidth-pagination.test.ts, line 64:
<comment>This test mutates the shared `USER_ID` fixture's organization membership, so parallel tests using the same user can observe the random org and become order-dependent. A dedicated seeded test user (or an isolated fixture identity) would keep the pagination regression data independent from other backend tests.</comment>
<file context>
@@ -0,0 +1,157 @@
+ beforeAll(async () => {
+ // created_by bootstraps org_users + org_super_admin role_bindings
+ await getSupabaseClient().from('orgs').insert({
+ created_by: USER_ID,
+ id: orgId,
+ management_email: USER_EMAIL,
</file context>





Summary (AI generated)
get_app_metricsin/statisticsorg dashboards so apps × days results are not silently cut at PostgRESTmax_rows(1000).Motivation (AI generated)
A user looking at their org dashboard of all apps saw no bandwidth, but opening one app showed bandwidth correctly. Root cause: org metrics return every app × day and hit the 1000-row PostgREST limit, dropping later
app_ids. The single-app RPC filters inside SQL first, so it stays under the limit and still looks fine.Business Impact (AI generated)
Restores correct org-wide bandwidth on the customer dashboard for orgs with many apps, so usage visibility matches what each app page already shows.
Test Plan (AI generated)
fetchAppMetricsRowspages past 1000 and keeps lateapp_idbandwidthmetricDayNumbermaps dates to day indexes/statisticsboth return its bandwidthGenerated with AI
Summary by CodeRabbit
New Features
Bug Fixes
Tests