-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code cache - cleanup in prep for chrome based code loading
- Loading branch information
Showing
18 changed files
with
302 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/vs/code/electron-browser/sharedProcess/contrib/codeCacheCleaner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { basename, dirname, join } from 'vs/base/common/path'; | ||
import { onUnexpectedError } from 'vs/base/common/errors'; | ||
import { Disposable } from 'vs/base/common/lifecycle'; | ||
import { Promises, rimraf } from 'vs/base/node/pfs'; | ||
import { IProductService } from 'vs/platform/product/common/productService'; | ||
import { RunOnceScheduler } from 'vs/base/common/async'; | ||
import { ILogService } from 'vs/platform/log/common/log'; | ||
|
||
export class CodeCacheCleaner extends Disposable { | ||
|
||
private readonly _DataMaxAge = this.productService.quality !== 'stable' | ||
? 1000 * 60 * 60 * 24 * 7 // roughly 1 week (insiders) | ||
: 1000 * 60 * 60 * 24 * 30 * 3; // roughly 3 months (stable) | ||
|
||
constructor( | ||
currentCodeCachePath: string | undefined, | ||
@IProductService private readonly productService: IProductService, | ||
@ILogService private readonly logService: ILogService | ||
) { | ||
super(); | ||
|
||
// Cached data is stored as user data and we run a cleanup task everytime | ||
// the editor starts. The strategy is to delete all files that are older than | ||
// 3 months (1 week respectively) | ||
if (currentCodeCachePath) { | ||
const scheduler = this._register(new RunOnceScheduler(() => { | ||
this.cleanUpCodeCaches(currentCodeCachePath); | ||
}, 30 * 1000 /* after 30s */)); | ||
scheduler.schedule(); | ||
} | ||
} | ||
|
||
private async cleanUpCodeCaches(currentCodeCachePath: string): Promise<void> { | ||
this.logService.info('[code cache cleanup]: Starting to clean up old code cache folders.'); | ||
|
||
try { | ||
const now = Date.now(); | ||
|
||
// The folder which contains folders of cached data. | ||
// Each of these folders is partioned per commit | ||
const codeCacheRootPath = dirname(currentCodeCachePath); | ||
const currentCodeCache = basename(currentCodeCachePath); | ||
|
||
const codeCaches = await Promises.readdir(codeCacheRootPath); | ||
await Promise.all(codeCaches.map(async codeCache => { | ||
if (codeCache === currentCodeCache) { | ||
return; // not the current cache folder | ||
} | ||
|
||
// Delete cache folder if old enough | ||
const codeCacheEntryPath = join(codeCacheRootPath, codeCache); | ||
const codeCacheEntryStat = await Promises.stat(codeCacheEntryPath); | ||
if (codeCacheEntryStat.isDirectory() && (now - codeCacheEntryStat.mtime.getTime()) > this._DataMaxAge) { | ||
this.logService.info(`[code cache cleanup]: Removing code cache folder ${codeCache}.`); | ||
|
||
return rimraf(codeCacheEntryPath); | ||
} | ||
})); | ||
} catch (error) { | ||
onUnexpectedError(error); | ||
} | ||
} | ||
} |
Oops, something went wrong.