Skip to content

Commit 6342037

Browse files
author
Tim Keir
committed
Ignore cache misses prior to fetch step
1 parent 878edb3 commit 6342037

3 files changed

Lines changed: 71 additions & 9 deletions

File tree

.yarn/versions/216387e5.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
releases:
2+
"@yarnpkg/core": patch
3+
4+
declined:
5+
- "@yarnpkg/plugin-catalog"
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-exec"
11+
- "@yarnpkg/plugin-file"
12+
- "@yarnpkg/plugin-git"
13+
- "@yarnpkg/plugin-github"
14+
- "@yarnpkg/plugin-http"
15+
- "@yarnpkg/plugin-init"
16+
- "@yarnpkg/plugin-interactive-tools"
17+
- "@yarnpkg/plugin-jsr"
18+
- "@yarnpkg/plugin-link"
19+
- "@yarnpkg/plugin-nm"
20+
- "@yarnpkg/plugin-npm"
21+
- "@yarnpkg/plugin-npm-cli"
22+
- "@yarnpkg/plugin-pack"
23+
- "@yarnpkg/plugin-patch"
24+
- "@yarnpkg/plugin-pnp"
25+
- "@yarnpkg/plugin-pnpm"
26+
- "@yarnpkg/plugin-stage"
27+
- "@yarnpkg/plugin-typescript"
28+
- "@yarnpkg/plugin-version"
29+
- "@yarnpkg/plugin-workspace-tools"
30+
- "@yarnpkg/builder"
31+
- "@yarnpkg/cli"
32+
- "@yarnpkg/doctor"
33+
- "@yarnpkg/extensions"
34+
- "@yarnpkg/nm"
35+
- "@yarnpkg/pnpify"
36+
- "@yarnpkg/sdks"

packages/yarnpkg-core/sources/Project.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,7 @@ export class Project {
10971097
mockedPackages: this.disabledLocators,
10981098
unstablePackages: this.conditionalLocators,
10991099
};
1100+
const initialCacheMisses = new Set(report.cacheMisses);
11001101

11011102
const fetcher = userFetcher || this.configuration.makeFetcher();
11021103
const fetcherOptions = {checksums: this.storedChecksums, project: this, cache, fetcher, report, cacheOptions};
@@ -1165,8 +1166,12 @@ export class Project {
11651166
? await this.cacheCleanup({cache, report})
11661167
: null;
11671168

1168-
if (report.cacheMisses.size > 0 || cleanInfo) {
1169-
const addedSizes = await Promise.all([...report.cacheMisses].map(async locatorHash => {
1169+
const fetchCacheMisses = [...report.cacheMisses].filter(locatorHash => {
1170+
return !initialCacheMisses.has(locatorHash);
1171+
});
1172+
1173+
if (fetchCacheMisses.length > 0 || cleanInfo) {
1174+
const addedSizes = await Promise.all(fetchCacheMisses.map(async locatorHash => {
11701175
const locator = this.storedPackages.get(locatorHash);
11711176
const checksum = this.storedChecksums.get(locatorHash) ?? null;
11721177

@@ -1178,7 +1183,7 @@ export class Project {
11781183

11791184
const finalSizeChange = addedSizes.reduce((sum, size) => sum + size, 0) - (cleanInfo?.size ?? 0);
11801185

1181-
const addedCount = report.cacheMisses.size;
1186+
const addedCount = fetchCacheMisses.length;
11821187
const removedCount = cleanInfo?.count ?? 0;
11831188

11841189
const addedLine = `${miscUtils.plural(addedCount, {

packages/yarnpkg-core/tests/Project.test.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {Cache, Configuration, Project, ThrowReport, structUtils, LocatorHash, Package} from '@yarnpkg/core';
2-
import {Filename, PortablePath, ppath, xfs} from '@yarnpkg/fslib';
3-
import LinkPlugin from '@yarnpkg/plugin-link';
4-
import PnpPlugin from '@yarnpkg/plugin-pnp';
5-
import v8 from 'v8';
1+
import {Cache, Configuration, Project, ThrowReport, structUtils, LocatorHash, Package, InstallMode} from '@yarnpkg/core';
2+
import {Filename, PortablePath, ppath, xfs} from '@yarnpkg/fslib';
3+
import LinkPlugin from '@yarnpkg/plugin-link';
4+
import PnpPlugin from '@yarnpkg/plugin-pnp';
5+
import v8 from 'v8';
66

7-
import {TestPlugin} from './TestPlugin';
7+
import {TestPlugin} from './TestPlugin';
88

99
const getConfiguration = (p: PortablePath) => {
1010
return Configuration.create(p, p, new Map([
@@ -301,4 +301,25 @@ describe(`Project`, () => {
301301
await expect(project.restoreInstallState()).resolves.toBeUndefined();
302302
});
303303
});
304+
305+
it(`should ignore cache misses recorded before the fetch step`, async() => {
306+
await xfs.mktempPromise(async dir => {
307+
await xfs.writeJsonPromise(ppath.join(dir, Filename.manifest), {name: `foo`});
308+
await xfs.writeFilePromise(ppath.join(dir, Filename.lockfile), ``);
309+
310+
const configuration = getConfiguration(dir);
311+
const {project} = await Project.find(configuration, dir);
312+
const cache = await Cache.find(configuration);
313+
const report = new ThrowReport();
314+
315+
report.cacheMisses.add(`preexisting-cache-miss` as LocatorHash);
316+
317+
await expect(project.fetchEverything({
318+
cache,
319+
report,
320+
mode: InstallMode.UpdateLockfile,
321+
persistProject: false,
322+
})).resolves.toBeUndefined();
323+
});
324+
});
304325
});

0 commit comments

Comments
 (0)