Skip to content

fix(statistics): org dashboard bandwidth truncated by PostgREST max_rows - #2738

Merged
riderx merged 6 commits into
mainfrom
cursor/bandwidth-report-scale-tests-536f
Jul 23, 2026
Merged

fix(statistics): org dashboard bandwidth truncated by PostgREST max_rows#2738
riderx merged 6 commits into
mainfrom
cursor/bandwidth-report-scale-tests-536f

Conversation

@riderx

@riderx riderx commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary (AI generated)

  • Paginate get_app_metrics in /statistics org dashboards so apps × days results are not silently cut at PostgREST max_rows (1000).
  • Index daily aggregates by metric date instead of array position.
  • Add unit + integration regression coverage for the org-all-apps empty bandwidth vs single-app OK failure mode.

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)

  • Unit test: fetchAppMetricsRows pages past 1000 and keeps late app_id bandwidth
  • Unit test: metricDayNumber maps dates to day indexes
  • Backend typecheck for pagination query chain
  • Integration: unpaginated org RPC drops late busy app; org + app /statistics both return its bandwidth
  • CI green (Supabase backend + Cloudflare workers + Playwright)

Generated with AI

Open in Web Open in Cursor 

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added a bandwidth trend chart to the admin dashboard.
    • Bandwidth values are displayed in gigabytes with updated labels.
  • Bug Fixes

    • Improved bandwidth aggregation across organizations and devices.
    • Prevented failures when optional queue tables are unavailable.
    • Avoided recording bandwidth for legacy downloads without device identification.
  • Tests

    • Added coverage for bandwidth reporting accuracy and performance at scale.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Bandwidth 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.

Changes

Bandwidth reporting

Layer / File(s) Summary
Organization bandwidth aggregation
supabase/functions/_backend/utils/cloudflare.ts
Typed row interfaces and mergeBandwidthUsageByOrg combine mapped device bandwidth and update metrics into organization totals.
Admin bandwidth trend dashboard
src/pages/admin/dashboard/updates.vue, messages/en.json
The dashboard loads bandwidth trends, converts bytes to GB, and renders a localized chart alongside global statistics.
Bandwidth reporting validation
tests/bandwidth-report-scale.test.ts, tests/bandwidth-report-scale.unit.test.ts, tests/files-bandwidth.unit.test.ts
Tests cover active-app queueing, metrics RPC results, organization aggregation at scale, SQL filtering, and downloads without device identifiers.

Queue cleanup migration

Layer / File(s) Summary
Guard missing queue metadata tables
supabase/migrations/20260723113511_cleanup_queue_skip_missing_tables.sql
Obsolete queue metadata is deleted only when pgmq.meta exists and the related queue relations are absent.

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
Loading

Possibly related PRs

Suggested reviewers: dalanir, wcaleniewolny

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the main change: fixing org dashboard bandwidth truncation caused by PostgREST row limits.
Description check ✅ Passed The description covers summary, motivation, impact, and test plan; only optional template sections like screenshots and checklist are missing.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing cursor/bandwidth-report-scale-tests-536f (98901d8) with main (42b818a)2

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (7e18610) during the generation of this report, so 42b818a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@cursor
cursor Bot temporarily deployed to deepsec-pr July 23, 2026 12:31 Inactive
@cursor
cursor Bot temporarily deployed to deepsec-pr July 23, 2026 12:37 Inactive
@cursor
cursor Bot temporarily deployed to deepsec-pr July 23, 2026 12:41 Inactive
@cursor
cursor Bot marked this pull request as ready for review July 23, 2026 12:48
@cursor

cursor Bot commented Jul 23, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@cursor
cursor Bot requested review from Dalanir and WcaleNieWolny July 23, 2026 12:49

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

Risk: medium. Not approving: Cursor Bugbot did not complete (check skipped due to usage limit), so automated review signal is missing. Human review is needed before merge.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@cursor cursor Bot changed the title test(stats): bandwidth report coverage at 800 clients / 8k inactive scale test(stats): harden bandwidth report coverage and restore admin trend Jul 23, 2026
@cursor
cursor Bot force-pushed the cursor/bandwidth-report-scale-tests-536f branch from ede0643 to daec587 Compare July 23, 2026 14:24
@cursor

cursor Bot commented Jul 23, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@cursor

cursor Bot commented Jul 23, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@cursor cursor Bot changed the title test(stats): harden bandwidth report coverage and restore admin trend feat(admin): restore global bandwidth trend and harden report tests Jul 23, 2026
@cursor
cursor Bot temporarily deployed to deepsec-pr July 23, 2026 14:25 Inactive

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7e18610 and daec587.

📒 Files selected for processing (7)
  • messages/en.json
  • src/pages/admin/dashboard/updates.vue
  • supabase/functions/_backend/utils/cloudflare.ts
  • supabase/migrations/20260723113511_cleanup_queue_skip_missing_tables.sql
  • tests/bandwidth-report-scale.test.ts
  • tests/bandwidth-report-scale.unit.test.ts
  • tests/files-bandwidth.unit.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

Comment thread tests/bandwidth-report-scale.unit.test.ts Outdated
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>
@cursor
cursor Bot force-pushed the cursor/bandwidth-report-scale-tests-536f branch from daec587 to 4914fc3 Compare July 23, 2026 15:01
@cursor
cursor Bot temporarily deployed to deepsec-pr July 23, 2026 15:01 Inactive
@cursor cursor Bot changed the title feat(admin): restore global bandwidth trend and harden report tests fix(statistics): org dashboard bandwidth truncated by PostgREST max_rows Jul 23, 2026
@cursor
cursor Bot marked this pull request as draft July 23, 2026 15:01
@cursor

cursor Bot commented Jul 23, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Open in Web View Automation 

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>
@cursor
cursor Bot temporarily deployed to deepsec-pr July 23, 2026 15:03 Inactive
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>
@cursor
cursor Bot temporarily deployed to deepsec-pr July 23, 2026 15:13 Inactive
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
@cursor
cursor Bot temporarily deployed to deepsec-pr July 23, 2026 15:21 Inactive
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
@cursor
cursor Bot temporarily deployed to deepsec-pr July 23, 2026 15:28 Inactive
@sonarqubecloud

Copy link
Copy Markdown

@cursor
cursor Bot marked this pull request as ready for review July 23, 2026 15:36
@cursor

cursor Bot commented Jul 23, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Confidence score: 4/5

  • In tests/org-statistics-bandwidth-pagination.test.ts, mutating the shared USER_ID fixture 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@riderx
riderx merged commit e05862a into main Jul 23, 2026
44 of 62 checks passed
@riderx
riderx deleted the cursor/bandwidth-report-scale-tests-536f branch July 23, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants