Skip to content

Cache breakdown responses in details modals#6274

Open
RobertJoonas wants to merge 6 commits intomasterfrom
add-stale-time-to-breakdown-cache
Open

Cache breakdown responses in details modals#6274
RobertJoonas wants to merge 6 commits intomasterfrom
add-stale-time-to-breakdown-cache

Conversation

@RobertJoonas
Copy link
Copy Markdown
Contributor

@RobertJoonas RobertJoonas commented Apr 22, 2026

Changes

  • Improve getStaleTime logic (and add tests):
    • 7d, 28d, 6mo, 12mo are now always considered historical as they exclude the current day
    • keep the same stale time for realtime (i.e. 30s)
    • keep the same stale time for historical periods (i.e. 12h)
    • for ongoing periods (those including now), give a much shorter stale time of 5min if 'day' (or shorter) graph interval is supported, or 15min otherwise. Use the validIntervals logic for determining that, which also takes comparison period into account.
  • plug staleTime into usePaginatedGetAPI, enabling cache for all breakdown modals, including Google Search Terms. Note that the current prod behaviour serves results from cache as well, but due to staleTime: 0 those results are instantly considered stale and a background re-fetch is triggered. Therefore, in terms of UX, nothing changes, other than not flashing a loading spinner on cache-hit.
  • add two tests for breakdown modal cache actually working

Tests

  • Automated tests have been added

Changelog

  • Does not need a changelog update

Documentation

  • This change does not need a documentation update

Dark mode

  • This PR does not change the UI

@github-actions
Copy link
Copy Markdown

Preview environment👷🏼‍♀️🏗️
PR-6274

@RobertJoonas RobertJoonas requested a review from apata April 23, 2026 08:51

describe(`${getStaleTime.name}`, () => {
describe('realtime periods', () => {
it('for realtime', () => {
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.

meganitpick, non-blocking: Can we refactor it( to test(? it works better if there's a verb right after

getStaleTime
} from './api-client'

const site = DEFAULT_SITE
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.

suggestion, non-blocking: If we refactor getStaleTime not to depend on arg named site but directly on the two properties from the site, it makes the test depend on less things. That way, we'd not need to import or fake a full site here, just the properties offset and statsBegin.

Comment on lines +149 to +153
const availableIntervals = validIntervals(
Object.fromEntries(
Object.entries(props).filter(([k, _v]) => k !== 'date')
) as GetIntervalProps
)
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.

issue, blocking: The cleaner way to exclude date would be to destructure const {date, ...rest} = props, const availableIntervals = validIntervals(rest), but we don't actually have to do it, because the function ignores the date prop if present. It doesn't make use of it. Checking locally, the line const availableIntervals = validIntervals(props) is valid according to typescript compiler.


const { selectedInterval, onIntervalClick, availableIntervals } =
useStoredInterval({
useStoredInterval(intervalStorageKey, {
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.

question, non-blocking: Why can't the hook contain the logic to derive the storage key? Seems totally within its limited responsibilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants