Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions scripts/lib/edge-cache-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
* 3. An agent that asks for Markdown still gets the 307 to the `.md` URL.
* 4. A request that carries a session cookie gets the anonymous render, and
* the page tells the browser to load the session itself.
* 5. Every page is stored under its own key: pages that differ only by query
* string render a different title or canonical URL.
* 5. Every board is stored under its own key: boards that differ only by query
* string render a different title or canonical URL. The bare path and the
* default range are one board, so they may share both.
*/

import { DEFAULT_TRENDING_RANGE } from '../../shared/trending-range'

/** The pages `nuxt.config.ts` gives an `edgeCache` rule. Each query is its own cache key. */
export const EDGE_CACHED_PATHS = ['/skills/trending', '/skills/trending?range=month', '/skills/trending?range=all']

Expand All @@ -28,6 +31,9 @@ const BROWSER_HEADERS = {
/** Opaque on purpose: the page must not read it, so it never needs to unseal. */
const SESSION_COOKIE = 'nuxt-session=edge-cache-check'

/** The bare path and the default range name one board, so one canonical URL. */
const DEFAULT_BOARD_ALIASES = new Set(['/skills/trending', `/skills/trending?range=${DEFAULT_TRENDING_RANGE}`])

/** `cf-cache-status` values that mean the edge answered without the Worker. */
const SERVED_FROM_CACHE = new Set(['HIT', 'STALE', 'UPDATING'])

Expand Down Expand Up @@ -241,7 +247,7 @@ export async function checkEdgeCache(dependencies: EdgeCacheCheckDependencies):
}

for (const [identity, sharing] of identities) {
if (sharing.length > 1)
if (sharing.length > 1 && !sharing.every(path => DEFAULT_BOARD_ALIASES.has(path)))
failures.push({ _tag: 'shared-cache-entry', paths: sharing, identity })
}

Expand Down
12 changes: 12 additions & 0 deletions test/unit/edge-cache-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ describe('checkEdgeCache', () => {
})
})

it('passes when the bare path and the default range render one board', async () => {
const paths = ['/skills/trending', '/skills/trending?range=month', '/skills/trending?range=all']
const result = await run(edge({
anonymous: (path, count) => ({
body: page(null, false, path === '/skills/trending?range=all' ? path : '/skills/trending'),
headers: { 'cf-cache-status': count === 1 ? 'MISS' : 'HIT' },
}),
}), paths)

expect(result._tag).toBe('passed')
})

it('retries a transient non-200 once before it fails a board', async () => {
const inner = edge()
let failedOnce = false
Expand Down