Skip to content

Commit

Permalink
fix(cache): correct revision
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 22, 2021
1 parent 9171e71 commit 728082b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/util/cache/repository/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('lib/util/cache/repository', () => {
});
expect(repositoryCache.getCache()).toEqual({
repository: 'abc/def',
scan: {},
revision: repositoryCache.CACHE_REVISION,
});
});
it('reads from cache and finalizes', async () => {
Expand All @@ -50,6 +50,6 @@ describe('lib/util/cache/repository', () => {
expect(fs.outputFile.mock.calls).toHaveLength(1);
});
it('gets', () => {
expect(repositoryCache.getCache()).toEqual({ scan: {} });
expect(repositoryCache.getCache()).toEqual({});
});
});
15 changes: 9 additions & 6 deletions lib/util/cache/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ function validate(config: RenovateConfig, input: any): Cache | null {
return null;
}

function createCache(repository?: string): Cache {
const res: Cache = Object.create({});
res.repository = repository;
res.revision = CACHE_REVISION;
return res;
}

export async function initialize(config: RenovateConfig): Promise<void> {
cache = null;
try {
Expand All @@ -87,15 +94,11 @@ export async function initialize(config: RenovateConfig): Promise<void> {
} catch (err) {
logger.debug({ cacheFileName }, 'Repository cache not found');
}
cache = cache || Object.create({ revision: CACHE_REVISION });
cache.repository = config.repository;
cache ||= createCache(config.repository);
}

export function getCache(): Cache {
cache = cache || Object.create({ revision: CACHE_REVISION });
delete cache.init;
cache.scan = cache.scan || Object.create({});
return cache;
return cache || createCache();
}

export async function finalize(): Promise<void> {
Expand Down
3 changes: 2 additions & 1 deletion lib/workers/repository/process/extract-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export async function extract(
const baseBranchSha = getBranchCommit(baseBranch);
let packageFiles: Record<string, PackageFile[]>;
const cache = getCache();
const cachedExtract = cache?.scan?.[baseBranch];
cache.scan ||= {};
const cachedExtract = cache.scan[baseBranch];
const configHash = hasha(JSON.stringify(config));
// istanbul ignore if
if (
Expand Down

0 comments on commit 728082b

Please sign in to comment.