Skip to content

Commit e06b74e

Browse files
authored
fix(presets/cache): do not cache internal presets (#41524)
1 parent 000c2f9 commit e06b74e

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

lib/config/presets/index.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,13 @@ describe('config/presets/index', () => {
617617
});
618618

619619
describe('getPreset', () => {
620+
it('does not use cache for internal presets', async () => {
621+
const memCacheGetSpy = vi.spyOn(memCache, 'get');
622+
expect(await presets.getPreset(':dependencyDashboard', {})).toBeDefined();
623+
expect(memCacheGetSpy).not.toHaveBeenCalled();
624+
expect(packageCache.get).not.toHaveBeenCalled();
625+
});
626+
620627
it('handles removed presets with a migration', async () => {
621628
const res = await presets.getPreset(':base', {});
622629
expect(res).toEqual({

lib/config/presets/index.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const presetSources: Record<string, PresetApi> = {
4646
github,
4747
gitlab,
4848
http,
49-
internal,
5049
local,
5150
npm,
5251
};
@@ -120,33 +119,49 @@ export async function getPreset(
120119
}
121120
const { presetSource, repo, presetPath, presetName, tag, params, rawParams } =
122121
parsePreset(preset);
123-
const cacheKey = `preset:${preset}`;
124-
const presetCachePersistence = GlobalConfig.get(
125-
'presetCachePersistence',
126-
false,
127-
);
128122

129123
let presetConfig: Preset | null | undefined;
130124

131-
if (presetCachePersistence) {
132-
presetConfig = await packageCache.get(presetCacheNamespace, cacheKey);
133-
} else {
134-
presetConfig = memCache.get(cacheKey);
135-
}
136-
137-
if (isNullOrUndefined(presetConfig)) {
138-
presetConfig = await presetSources[presetSource].getPreset({
125+
if (presetSource === 'internal') {
126+
presetConfig = internal.getPreset({
139127
repo,
140128
presetPath,
141129
presetName,
142130
tag,
143131
});
132+
} else {
133+
const cacheKey = `preset:${preset}`;
134+
const presetCachePersistence = GlobalConfig.get(
135+
'presetCachePersistence',
136+
false,
137+
);
138+
144139
if (presetCachePersistence) {
145-
await packageCache.set(presetCacheNamespace, cacheKey, presetConfig, 15);
140+
presetConfig = await packageCache.get(presetCacheNamespace, cacheKey);
146141
} else {
147-
memCache.set(cacheKey, presetConfig);
142+
presetConfig = memCache.get(cacheKey);
143+
}
144+
145+
if (isNullOrUndefined(presetConfig)) {
146+
presetConfig = await presetSources[presetSource].getPreset({
147+
repo,
148+
presetPath,
149+
presetName,
150+
tag,
151+
});
152+
if (presetCachePersistence) {
153+
await packageCache.set(
154+
presetCacheNamespace,
155+
cacheKey,
156+
presetConfig,
157+
15,
158+
);
159+
} else {
160+
memCache.set(cacheKey, presetConfig);
161+
}
148162
}
149163
}
164+
150165
if (!presetConfig) {
151166
throw new Error(PRESET_DEP_NOT_FOUND);
152167
}

0 commit comments

Comments
 (0)