Skip to content

fix: cache /data metrics for instant reload#901

Open
riderx wants to merge 2 commits into
mainfrom
fix/data-page-cache-and-stats
Open

fix: cache /data metrics for instant reload#901
riderx wants to merge 2 commits into
mainfrom
fix/data-page-cache-and-stats

Conversation

@riderx

@riderx riderx commented Jul 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Cache live metrics in sessionStorage (5 min TTL, stale-while-revalidate) so a second reload paints instantly.
  • Public visitor-facing copy left unchanged.

Backend success-rate source fix: Cap-go/capgo.app#2706.

Visual

/data cache

Test plan

  • Open /data/, wait for metrics, reload — second load should show numbers immediately
  • Confirm visitor-facing copy does not mention internal data sources

Made with Cursor

Use sessionStorage so a second reload in the same session paints instantly, and align the success-rate copy with the Capgo global_stats source.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The data page now describes Live Update reliability using the global_stats snapshot, updates its KPI labels, and loads metrics through session-based caching with timeout handling and conditional fallback states.

Changes

Live Update reliability

Layer / File(s) Summary
Reliability presentation and asset
.github/pr-assets/data-page-cache-global-stats.webp, apps/web/src/pages/data.astro
Page copy and KPI labels now describe the 30-day success-rate view sourced from global_stats; the WebP asset was replaced.
Cached metrics loading
apps/web/src/pages/data.astro
Metrics use cache-first session storage, fresh fetches with abort timeouts, response normalization, timestamped writes, and conditional unavailable-state rendering.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant data.astro
  participant sessionStorage
  participant MetricsEndpoint
  participant MetricsUI
  data.astro->>sessionStorage: Read cached metrics
  sessionStorage-->>data.astro: Return cached metrics or no entry
  data.astro->>MetricsUI: Render cached metrics when available
  data.astro->>MetricsEndpoint: Fetch fresh metrics with abort timeout
  MetricsEndpoint-->>data.astro: Return raw metrics payload
  data.astro->>sessionStorage: Store payload and timestamp
  data.astro->>MetricsUI: Render normalized metrics or unavailable state
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: instant /data reload caching and updated global_stats copy.
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.

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

@riderx
riderx marked this pull request as ready for review July 16, 2026 13:49
@cursor

cursor Bot commented Jul 16, 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_65f05e9a-92f7-4d41-9188-d12b21a788b7)

@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 completed with status skipping (usage limit reached), so the required automated review signal is incomplete. Assigned reviewers for human review.

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: 2

🤖 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 `@apps/web/src/pages/data.astro`:
- Line 38: Add an aria-live="polite" region to the success-rate KPI rendered in
the data page, preferably with aria-atomic="true", so updates made by
renderMetrics() are announced to screen readers while preserving the existing
value and data-kpi="success-rate" marker.
- Around line 315-316: Update the cache validation around parsed.savedAt in the
metrics cache parsing flow to capture the current time and reject entries whose
savedAt is later than that time, in addition to the existing type and TTL
checks. Only call normalizeMetrics for non-future, non-expired entries.
🪄 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: a6de520e-0a39-427b-862c-34b9ce4b3d84

📥 Commits

Reviewing files that changed from the base of the PR and between 1646ff4 and c68b5bb.

📒 Files selected for processing (2)
  • .github/pr-assets/data-page-cache-global-stats.webp
  • apps/web/src/pages/data.astro
🔗 Linked repositories identified

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

  • Cap-go/capacitor-updater (manual)

Comment thread apps/web/src/pages/data.astro Outdated

<div class="data-kpis" aria-label="Reliability summary">
<div><p>30-day success rate</p><strong data-kpi="success-rate">—</strong></div>
<div><p>Success rate</p><strong data-kpi="success-rate">—</strong></div>

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Announce the asynchronously populated success rate.

renderMetrics() replaces this value after cache and network loads, but it is not in a live region. Add aria-live="polite" (and preferably aria-atomic="true") so screen-reader users receive the KPI update.

Proposed fix
- <div><p>Success rate</p><strong data-kpi="success-rate">—</strong></div>
+ <div><p>Success rate</p><strong data-kpi="success-rate" aria-live="polite" aria-atomic="true">—</strong></div>

As per coding guidelines, “Dynamic content must use aria-live regions for accessibility.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div><p>Success rate</p><strong data-kpi="success-rate">—</strong></div>
<div><p>Success rate</p><strong data-kpi="success-rate" aria-live="polite" aria-atomic="true">—</strong></div>
🤖 Prompt for 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.

In `@apps/web/src/pages/data.astro` at line 38, Add an aria-live="polite" region
to the success-rate KPI rendered in the data page, preferably with
aria-atomic="true", so updates made by renderMetrics() are announced to screen
readers while preserving the existing value and data-kpi="success-rate" marker.

Source: Coding guidelines

Comment on lines +315 to +316
if (typeof parsed.savedAt !== 'number' || Date.now() - parsed.savedAt > METRICS_CACHE_TTL_MS) return null
return normalizeMetrics(parsed.payload)

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the relevant file and inspect the metrics cache logic.
printf '\n== file list ==\n'
git ls-files 'apps/web/src/pages/data.astro' 'apps/web/src/**/config*' 'apps/web/src/**/*metrics*' | sed 's#^`#-` #'

printf '\n== relevant lines in apps/web/src/pages/data.astro ==\n'
nl -ba apps/web/src/pages/data.astro | sed -n '260,340p'

printf '\n== search for METRICS_CACHE_TTL_MS and savedAt usage ==\n'
rg -n "METRICS_CACHE_TTL_MS|savedAt|normalizeMetrics|cache" apps/web/src/pages/data.astro apps/web/src -g '!**/dist/**' -g '!**/build/**' || true

Repository: Cap-go/website

Length of output: 565


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== data.astro excerpt ==\n'
sed -n '280,340p' apps/web/src/pages/data.astro

printf '\n== savedAt / metrics cache references ==\n'
rg -n "savedAt|METRICS_CACHE_TTL_MS|normalizeMetrics|metrics cache|cache" apps/web/src/pages/data.astro apps/web/src -g '!**/dist/**' -g '!**/build/**' || true

Repository: Cap-go/website

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '300,335p' apps/web/src/pages/data.astro

printf '\n--\n'

rg -n "savedAt|METRICS_CACHE_TTL_MS|normalizeMetrics" apps/web/src/pages/data.astro

Repository: Cap-go/website

Length of output: 2069


Reject future-dated cache entries. savedAt values ahead of Date.now() bypass this TTL check, so stale metrics can be treated as fresh when revalidation fails. Add a savedAt <= now guard before accepting the cache.

🤖 Prompt for 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.

In `@apps/web/src/pages/data.astro` around lines 315 - 316, Update the cache
validation around parsed.savedAt in the metrics cache parsing flow to capture
the current time and reject entries whose savedAt is later than that time, in
addition to the existing type and TTL checks. Only call normalizeMetrics for
non-future, non-expired entries.

@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 2 files

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="apps/web/src/pages/data.astro">

<violation number="1" location="apps/web/src/pages/data.astro:34">
P3: Readers can no longer tell that each app/device/UTC-day combination is classified by its eventual install outcome, so the displayed success rate lacks its counting definition. Please retain that definition while naming `global_stats` as the source.

(Based on your team's feedback about naming the success combination.) [FEEDBACK_USED].</violation>
</file>

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

Fix all with cubic | Re-trigger cubic

Comment thread apps/web/src/pages/data.astro Outdated
<h2 id="reliability-title">Daily success rate</h2>
</div>
<p>Counted per app, device, and UTC day. If that combination eventually installs successfully, it counts as success.</p>
<p>Success rate matches Capgo global_stats. Failure reasons stay deduplicated by app, device, and UTC day.</p>

@cubic-dev-ai cubic-dev-ai Bot Jul 16, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: Readers can no longer tell that each app/device/UTC-day combination is classified by its eventual install outcome, so the displayed success rate lacks its counting definition. Please retain that definition while naming global_stats as the source.

(Based on your team's feedback about naming the success combination.) .

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/web/src/pages/data.astro, line 34:

<comment>Readers can no longer tell that each app/device/UTC-day combination is classified by its eventual install outcome, so the displayed success rate lacks its counting definition. Please retain that definition while naming `global_stats` as the source.

(Based on your team's feedback about naming the success combination.) .</comment>

<file context>
@@ -31,13 +31,13 @@ const content = {
             <h2 id="reliability-title">Daily success rate</h2>
           </div>
-          <p>Counted per app, device, and UTC day. If that combination eventually installs successfully, it counts as success.</p>
+          <p>Success rate matches Capgo global_stats. Failure reasons stay deduplicated by app, device, and UTC day.</p>
         </div>
 
</file context>
Suggested change
<p>Success rate matches Capgo global_stats. Failure reasons stay deduplicated by app, device, and UTC day.</p>
<p>Success rate matches Capgo global_stats: each app, device, and UTC-day combination counts as successful if it eventually installs successfully. Failure reasons use the same deduplication unit.</p>
Fix with cubic

Comment thread apps/web/src/pages/data.astro Outdated
@cursor
cursor Bot requested a review from WcaleNieWolny July 16, 2026 14:10

@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. Cursor Bugbot did not complete successfully (check skipped due to usage limit), so I cannot approve automatically. WcaleNieWolny assigned for human review.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

Keep the sessionStorage cache; drop visitor-facing global_stats wording that was not requested.

Co-authored-by: Cursor <cursoragent@cursor.com>
@riderx riderx changed the title fix: instant /data reload cache + global_stats copy fix: cache /data metrics for instant reload Jul 16, 2026
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant