Skip to content

Commit

Permalink
fix: drop cache for new majors (#1419)
Browse files Browse the repository at this point in the history
currently when new majors are introduced we need to shift around
branches / older versions need to be rebuild, so we invalidate the cache
here when a new major is introduced
  • Loading branch information
reggi authored Dec 18, 2024
1 parent df8e6e5 commit 6fcf10c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ const main = async ({loglevel, releases: rawReleases, useCurrent, navPath, conte
}
})

/**
* this voids the cache when a new version is added to release.json / not in the cli-cache.json
* this is done so that the previous major versions nav can be reset to legacy and pages can be droped from its variant
*/
cache?.voidOnNewKey(releases.map(v => v.id))

const updates = await Promise.all(
releases.map(r => extractRelease(r, {cache, contentPath, baseNav: navData, prerelease})),
).then(r => r.filter(Boolean))
Expand Down
13 changes: 13 additions & 0 deletions cli/lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const fs = require('fs/promises')

/** cache npm cli version shas to NOT pull down changes we already have */
class CacheVersionSha {
shouldVoid = false

constructor(cache, path) {
this.cache = cache
this.path = path
Expand All @@ -11,6 +13,16 @@ class CacheVersionSha {
return new CacheVersionSha(JSON.parse(await fs.readFile(path, 'utf-8')), path)
}

get keys() {
return Object.keys(this.cache)
}

voidOnNewKey(keys) {
if (keys.length !== this.keys.length || !keys.every(key => this.keys.includes(key))) {
this.shouldVoid = true
}
}

async save() {
const sortedCache = {}
Object.keys(this.cache)
Expand All @@ -33,6 +45,7 @@ class CacheVersionSha {
}

same(id, value) {
if (this.shouldVoid) return false
return this.cache[id] === value
}
}
Expand Down

0 comments on commit 6fcf10c

Please sign in to comment.