Skip to content

Stop the journal sidebar showing API responses cached before October - #498

Merged
laffer1 merged 1 commit into
masterfrom
api-cache-bust
Nov 3, 2026
Merged

laffer1 merged 1 commit into
masterfrom
api-cache-bust

Conversation

@laffer1

@laffer1 laffer1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

The journal sidebar on /users/mbsd showed the recent entries and archive counts as of 22 July, even though the API returns current data.

Cause

  • Until 6c2a70c (26 October) /api/** responses carried no Cache-Control from the app. A browser could store one of these responses and treat it as fresh for a long time, perhaps because of the long expiry the front-end proxy adds.
  • While a stored copy counts as fresh, the browser doesn't ask the server at all. So the no-cache, private sent today never reaches it.
  • The server itself is right: curl https://www.justjournal.com/api/entry/mbsd/recent returns the newest entries with Cache-Control: no-cache and an ETag matching the body.

Change

users.html calls $.ajaxSetup({cache: false}) before its sidebar requests. jQuery then adds _=<timestamp> to every GET on the page. No stored copy has that URL, so each one goes to the server.

The cost is that these small requests no longer get 304s; the API already tells browsers to check every time.

Testing

  • UsersTemplateTests and UsersControllerTests: 69 tests, 0 failures.
  • Not verified in a browser that has the July copies stored. Clearing that browser's cache also fixes it for that one browser.

Not covered

Other pages that call the API, such as public-pages.js for the mood, location and security lists, aren't changed. Those lists rarely change, so stale copies of them matter less.

🤖 Generated with Claude Code

Summary by Sourcery

Bug Fixes:

  • Prevent stale browser-cached API responses from keeping the journal sidebar’s recent entries and archive counts outdated.

The API sent no Cache-Control until 6c2a70c (26 October), so a browser
could keep its copy of a sidebar list, such as the recent entries or
the archive counts, as fresh and keep showing it without asking the
server. The no-cache header sent now never reaches a browser that
doesn't ask. Turning off jQuery's cache for the journal page adds a
query string that no stored copy matches, so every list is fetched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The users page disables jQuery AJAX caching before loading journal sidebar data, adding a timestamp to GET URLs so browsers cannot reuse stale API responses cached before the server began sending appropriate cache directives.

Sequence diagram for cache-busted journal sidebar API requests

sequenceDiagram
    participant Browser
    participant UsersPage
    participant API

    Browser->>UsersPage: Load /users/mbsd
    UsersPage->>UsersPage: $.ajaxSetup({cache: false})
    UsersPage->>API: GET /api/entry/mbsd/recent?_=timestamp
    API-->>UsersPage: Current journal entries
    UsersPage->>API: GET /api/entry/mbsd/archive?_=timestamp
    API-->>UsersPage: Current archive counts
Loading

File-Level Changes

Change Details Files
Force journal sidebar API GETs to bypass potentially stale browser-cached URLs.
  • Configure jQuery AJAX requests on the users page with caching disabled.
  • Rely on jQuery’s timestamp query parameter so each sidebar request reaches the server instead of reusing pre-October cached responses.
  • Accept loss of conditional 304 responses because the API already requires revalidation on every request.
src/main/resources/templates/users.html

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

@laffer1

laffer1 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@deepsource-io

deepsource-io Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

DeepSource Code Review

We reviewed changes in bace761...94cc32c on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Nov 3, 2026 4:48a.m. Review ↗
Java Nov 3, 2026 4:48a.m. Review ↗
Shell Nov 3, 2026 4:48a.m. Review ↗
JavaScript Nov 3, 2026 4:48a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@laffer1
laffer1 merged commit 8e92b65 into master Nov 3, 2026
10 of 11 checks passed
@laffer1
laffer1 deleted the api-cache-bust branch November 3, 2026 04:49

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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