Skip to content

Serve Dive Log history actions from the shared data cache - #337

Merged
devin-ai-integration[bot] merged 2 commits into
masterfrom
devin/1796220435-cache-dive-log-history
Dec 2, 2026
Merged

devin-ai-integration[bot] merged 2 commits into
masterfrom
devin/1796220435-cache-dive-log-history

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Remediates code-scan finding sfind-f9e219312b4343069479b36e0ca794bb: the anonymous server actions loadDiveLogHistory / loadDiveLogSiteHistory passed fresh: true to loadPublicDivesFromApi, which getJson turned into cache: "no-store", so every anonymous call re-walked up to MAX_PAGES (200) uncached upstream pages.

- loadPublicDivesFromApi({ startDate, fresh: true })
+ sharedLoad(`range:${startDate ?? "all"}`, () => loadPublicDivesFromApi({ startDate }))

  // getJson
- ...(fresh ? { cache: "no-store" } : { next: { revalidate: 3600 } })
+ headers: { Accept: "application/json", "X-Cache-Window": String(cacheWindow()) },
+ next: { revalidate: PUBLIC_DIVING_API_REVALIDATE_SECONDS }
  • The fresh option is removed entirely, so no caller can request uncached pages any more; every upstream page goes through the shared Next data cache (hourly, same as the page).
  • X-Cache-Window (hourly bucket) is part of Next's fetch cache key. Without it, Next serves an expired entry once while refreshing in the background, so after a long idle the first wider load could be arbitrarily old (e.g. missing dives older than the page's 14-day window). Staleness is now bounded to one hour.
  • createSharedLoader (lib/public-diving/shared-load.ts, server-only) coalesces concurrent identical loads per instance and reuses a successful result for 5 min (max 64 keys; keys are range:<startDate|all> / site:<resolved siteId>, so the input space is already bounded by the existing range allowlist and site lookup). Rejections are evicted, so "Try again" reaches the API.
  • UI behavior is unchanged: the client merges wider chunks with the page's list by dive id. Docs updated in docs/PUBLIC_DIVING_API.md.

Verification

  • npm run lint, npm run typecheck, npm test (789 tests), npm run check, npm run build:test: all pass.
  • Playwright desktop-chromium: 154 passed, 7 skipped.
  • Runtime check (next start build against a local 250-dive mock API): first loadDiveLogHistory("all") hit 3 upstream pages; 5 concurrent + 5 sequential repeats hit 0; 3 site loads hit the sites list + 2 pages once; invalid range rejected with no upstream call; after a server restart (empty in-memory loader) a repeat hit 0 upstream pages (served from the data cache). Browser: selecting "All" range still widens the list.

No Vercel/Firewall or env changes are required.

Link to Devin session: https://app.devin.ai/sessions/ab448ba992124a9da8ad821c37071248
Open in Devin Desktop: https://app.devin.ai/desktop/session/ab448ba992124a9da8ad821c37071248?variant=devin
Requested by: @spizeck


🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review

Summary by Sourcery

Keep anonymous Dive Log history requests on the shared data cache to prevent repeated uncached upstream page walks.

Bug Fixes:

  • Serve anonymous Dive Log history and site-history requests through the shared hourly data cache instead of allowing uncached upstream page walks.

Enhancements:

  • Coalesce identical history loads on a server instance and reuse successful results for five minutes, while allowing retries after failures.
  • Merge hourly cache-window identifiers into public API requests so stale cached pages are refreshed in a new hourly window.

Documentation:

  • Update the public diving API documentation to describe caching, request reuse, and how cached history interacts with the page list.

Tests:

  • Add coverage for shared-load concurrency, TTL and capacity limits, failure retries, and hourly cache behavior.

Co-Authored-By: Chad <chadnuttall1@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
seasaba-web Ready Ready Preview Dec 2, 2026 2:18pm UTC

Request Review

@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Sorry @devin-ai-integration[bot], this account has used its review budget of 1,500,000 diff characters for the last 7 days.

You can request another review in 2 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

Ask an organization administrator to verify that this bot has an active assigned CodeRabbit review seat. See the seat-assignment guide. After the seat is confirmed, request a review again.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6132a79a-322e-4e39-8d90-0f838c8f0b79

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Co-Authored-By: Chad <chadnuttall1@gmail.com>
@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

API

Keep public Dive Log history loads on the shared hourly data cache and remove the uncached fresh option from the dives client interface.

  • lib/public-diving/client.ts L67-71, L76-86 (+3 small edits)

Uses of the API

Route anonymous range and site history actions through a bounded per-instance loader so identical requests share successful results and failures remain retryable.

  • app/(en)/(content)/dive-log/actions.ts L9-18, L25-29 (+2 small edits)

Implementation

Add a server-only shared loader that coalesces in-flight work, retains successes for a TTL, evicts failures, and caps retained keys.

  • lib/public-diving/shared-load.ts L1-43

Documentation

Document the new cache behavior, bounded staleness, and client-side merge rationale for Dive Log history actions.

  • docs/PUBLIC_DIVING_API.md L134-141

Tests

Update action tests for cached loads and cover reuse, key separation, and retry behavior after failures.

  • tests/unit/dive-log-actions.test.ts L4-7, L17-21, L54-76 (+3 small edits)

Verify the dives client uses the shared data cache and rotates its cache-key header hourly.

  • tests/unit/public-diving-client.test.ts L121 (removed lines), L123 (removed lines), L127-157

Test shared-loader coalescing, TTL reuse, failure eviction, and entry limits.

  • tests/unit/shared-load.test.ts L1-38

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@sourcery-ai sourcery-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.

Sourcery assessment

Approved.

@devin-ai-integration
devin-ai-integration Bot merged commit 1135201 into master Dec 2, 2026
12 checks passed
@devin-ai-integration
devin-ai-integration Bot deleted the devin/1796220435-cache-dive-log-history branch December 2, 2026 16:00

This branch was successfully deployed

1 active deployment
Preview — d6618cd9 Deployed Dec 2, 2026 by vercel[bot]
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