Skip to content

Commit 2495fdd

Browse files
committed
Apply /simplify: share META_PREFIX/TARBALL_PREFIX with the key builders
The expiry sweep hardcoded ['meta/', 'tarball/'] kept in sync with metaKey/ tarballKey only by a 'must match' comment; a prefix rename would silently desync the cron (it would stop matching and R2 would leak with no error). Export the two prefixes from r2Cache, use them in both the key builders and the sweep.
1 parent dc03e4d commit 2495fdd

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/cache/r2Cache.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
/** R2 object keys and the public URL for a generated preview build. */
22
import type { Env } from '../config'
33

4+
// Per-version object key prefixes. Shared with the expiry sweep
5+
// (cleanupExpiredArtifacts), so a rename here can't silently desync it.
6+
export const TARBALL_PREFIX = 'tarball/'
7+
export const META_PREFIX = 'meta/'
8+
49
export function tarballKey(name: string, version: string): string {
5-
return `tarball/${name}/${version}.tgz`
10+
return `${TARBALL_PREFIX}${name}/${version}.tgz`
611
}
712

813
/** Public URL of a preview tarball (the inverse of parseTarballPath). */
@@ -15,7 +20,7 @@ export function tarballUrl(
1520
}
1621

1722
export function metaKey(name: string, version: string): string {
18-
return `meta/${name}/${version}.json`
23+
return `${META_PREFIX}${name}/${version}.json`
1924
}
2025

2126
/**

src/preview/cleanupExpired.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { Env } from '../config'
2+
import { META_PREFIX, TARBALL_PREFIX } from '../cache/r2Cache'
23
import { REF_TTL_MS } from './getConfiguredRefs'
34

4-
// R2 key prefixes for the per-version preview artifacts. Must match `metaKey` /
5-
// `tarballKey` in ../cache/r2Cache. NOT `meta-index/` or `refs/`: those are the
6-
// live indexes (self-pruned on write), not per-version orphans.
7-
const ARTIFACT_PREFIXES = ['meta/', 'tarball/']
5+
// The per-version artifact prefixes (shared with the key builders). NOT
6+
// `meta-index/` or `refs/`: those are the live indexes (self-pruned on write),
7+
// not per-version orphans, and their prefixes are disjoint from these.
8+
const ARTIFACT_PREFIXES = [META_PREFIX, TARBALL_PREFIX]
89

910
/**
1011
* Delete per-version preview artifacts (meta + tarball) whose ref TTL has lapsed,

0 commit comments

Comments
 (0)