Restore/cache deduplicated files in parallel

This commit is contained in:
Daz DeBoer 2021-09-11 20:56:40 -06:00
parent 4b92b8d013
commit 5a90152b1f
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
3 changed files with 58 additions and 53 deletions

2
dist/main/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/post/index.js vendored

File diff suppressed because one or more lines are too long

View file

@ -42,38 +42,36 @@ export class GradleUserHomeCache extends AbstractCache {
const globber = await glob.create(markerFilePatterns)
const markerFiles = await globber.glob()
const processes: Promise<void>[] = []
for (const markerFile of markerFiles) {
const p = this.restoreDeduplicatePath(markerFile)
processes.push(p)
}
await Promise.all(processes)
}
private async restoreDeduplicatePath(markerFile: string): Promise<void> {
const targetFile = markerFile.substring(
0,
markerFile.length - MARKER_FILE_EXTENSION.length
)
core.info(
`Found marker file: ${markerFile}. Looking for ${targetFile}`
)
core.info(`Found marker file: ${markerFile}. Looking for ${targetFile}`)
if (!fs.existsSync(targetFile)) {
const key = path.relative(this.getGradleUserHome(), targetFile)
const cacheKey = `gradle-dedup-${key}`
core.info(`Cache key: ${cacheKey}. Cache path: ${targetFile}`)
const restoreKey = await cache.restoreCache(
[targetFile],
cacheKey
)
const restoreKey = await cache.restoreCache([targetFile], cacheKey)
if (restoreKey) {
core.info(
`Restored ${cacheKey} from cache to ${targetFile}`
)
core.info(`Restored ${cacheKey} from cache to ${targetFile}`)
} else {
core.info(
`Did NOT restore from ${cacheKey} to ${targetFile}`
)
core.info(`Did NOT restore from ${cacheKey} to ${targetFile}`)
}
} else {
core.info(`Target file already exists: ${targetFile}`)
}
}
}
private async reportCacheEntrySize(): Promise<void> {
const gradleUserHome = path.resolve(os.homedir(), '.gradle')
@ -99,7 +97,15 @@ export class GradleUserHomeCache extends AbstractCache {
const globber = await glob.create(targetFilePatterns)
const targetFiles = await globber.glob()
const processes: Promise<void>[] = []
for (const targetFile of targetFiles) {
const p = this.cacheDeplucatePath(targetFile)
processes.push(p)
}
await Promise.all(processes)
}
private async cacheDeplucatePath(targetFile: string): Promise<void> {
core.info(`Deduplicate caching: ${targetFile}`)
const markerFile = `${targetFile}${MARKER_FILE_EXTENSION}`
@ -133,7 +139,6 @@ export class GradleUserHomeCache extends AbstractCache {
// Delete the target file
fs.unlinkSync(targetFile)
}
}
protected cacheOutputExists(): boolean {
// Need to check for 'caches' directory to avoid incorrect detection on MacOS agents