From d536410f161fb3eeac25cc0e2388d3eba77339e3 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Wed, 24 Jan 2018 11:51:44 +0100 Subject: [PATCH] extension report cache and load --- .../common/extensionManagement.ts | 2 +- .../common/extensionManagementIpc.ts | 8 ++- .../node/extensionGalleryService.ts | 6 -- .../node/extensionManagementService.ts | 60 +++++++++++++++++-- 4 files changed, 62 insertions(+), 14 deletions(-) diff --git a/src/vs/platform/extensionManagement/common/extensionManagement.ts b/src/vs/platform/extensionManagement/common/extensionManagement.ts index 6512e977822..5eb1cb408ab 100644 --- a/src/vs/platform/extensionManagement/common/extensionManagement.ts +++ b/src/vs/platform/extensionManagement/common/extensionManagement.ts @@ -232,7 +232,6 @@ export enum StatisticType { export interface IReportedExtension { id: IExtensionIdentifier; malicious: boolean; - slow: boolean; } export interface IExtensionGalleryService { @@ -280,6 +279,7 @@ export interface IExtensionManagementService { installFromGallery(extension: IGalleryExtension): TPromise; uninstall(extension: ILocalExtension, force?: boolean): TPromise; getInstalled(type?: LocalExtensionType): TPromise; + getExtensionsReport(): TPromise; updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise; } diff --git a/src/vs/platform/extensionManagement/common/extensionManagementIpc.ts b/src/vs/platform/extensionManagement/common/extensionManagementIpc.ts index 15bb2aa58df..9cb9488880e 100644 --- a/src/vs/platform/extensionManagement/common/extensionManagementIpc.ts +++ b/src/vs/platform/extensionManagement/common/extensionManagementIpc.ts @@ -7,7 +7,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc'; -import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, IGalleryExtension, LocalExtensionType, DidUninstallExtensionEvent, IExtensionIdentifier, IGalleryMetadata } from './extensionManagement'; +import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, IGalleryExtension, LocalExtensionType, DidUninstallExtensionEvent, IExtensionIdentifier, IGalleryMetadata, IReportedExtension } from './extensionManagement'; import Event, { buffer } from 'vs/base/common/event'; export interface IExtensionManagementChannel extends IChannel { @@ -19,6 +19,7 @@ export interface IExtensionManagementChannel extends IChannel { call(command: 'installFromGallery', extension: IGalleryExtension): TPromise; call(command: 'uninstall', args: [ILocalExtension, boolean]): TPromise; call(command: 'getInstalled'): TPromise; + call(command: 'getExtensionsReport'): TPromise; call(command: string, arg?: any): TPromise; } @@ -47,6 +48,7 @@ export class ExtensionManagementChannel implements IExtensionManagementChannel { case 'uninstall': return this.service.uninstall(arg[0], arg[1]); case 'getInstalled': return this.service.getInstalled(arg); case 'updateMetadata': return this.service.updateMetadata(arg[0], arg[1]); + case 'getExtensionsReport': return this.service.getExtensionsReport(); } return undefined; } @@ -89,4 +91,8 @@ export class ExtensionManagementChannelClient implements IExtensionManagementSer updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise { return this.channel.call('updateMetadata', [local, metadata]); } + + getExtensionsReport(): TPromise { + return this.channel.call('getExtensionsReport'); + } } \ No newline at end of file diff --git a/src/vs/platform/extensionManagement/node/extensionGalleryService.ts b/src/vs/platform/extensionManagement/node/extensionGalleryService.ts index ae9aa3ca924..81b8e3cc744 100644 --- a/src/vs/platform/extensionManagement/node/extensionGalleryService.ts +++ b/src/vs/platform/extensionManagement/node/extensionGalleryService.ts @@ -743,12 +743,6 @@ export class ExtensionGalleryService implements IExtensionGalleryService { map.set(id, ext); } - for (const id of result.slow) { - const ext = map.get(id) || { id: { id }, malicious: false, slow: true }; - ext.slow = true; - map.set(id, ext); - } - return TPromise.as(values(map)); }); }); diff --git a/src/vs/platform/extensionManagement/node/extensionManagementService.ts b/src/vs/platform/extensionManagement/node/extensionManagementService.ts index 84ab67e438e..7adb4f33231 100644 --- a/src/vs/platform/extensionManagement/node/extensionManagementService.ts +++ b/src/vs/platform/extensionManagement/node/extensionManagementService.ts @@ -19,7 +19,8 @@ import { IGalleryExtension, IExtensionManifest, IGalleryMetadata, InstallExtensionEvent, DidInstallExtensionEvent, DidUninstallExtensionEvent, LocalExtensionType, StatisticType, - IExtensionIdentifier + IExtensionIdentifier, + IReportedExtension } from 'vs/platform/extensionManagement/common/extensionManagement'; import { getGalleryExtensionIdFromLocal, adoptToGalleryExtensionId, areSameExtensions, getGalleryExtensionId, groupByExtension } from 'vs/platform/extensionManagement/common/extensionManagementUtil'; import { localizeManifest } from '../common/extensionNls'; @@ -103,8 +104,9 @@ export class ExtensionManagementService implements IExtensionManagementService { private extensionsPath: string; private uninstalledPath: string; - private userDataPath: string; + private reportedPath: string; private uninstalledFileLimiter: Limiter; + private reportedExtensions: TPromise; private disposables: IDisposable[] = []; private readonly _onInstallExtension = new Emitter(); @@ -122,20 +124,24 @@ export class ExtensionManagementService implements IExtensionManagementService { onDidUninstallExtension: Event = this._onDidUninstallExtension.event; constructor( - @IEnvironmentService environmentService: IEnvironmentService, + @IEnvironmentService private environmentService: IEnvironmentService, @IChoiceService private choiceService: IChoiceService, @IExtensionGalleryService private galleryService: IExtensionGalleryService, - @ILogService private logService: ILogService, + @ILogService private logService: ILogService ) { this.extensionsPath = environmentService.extensionsPath; this.uninstalledPath = path.join(this.extensionsPath, '.obsolete'); - this.userDataPath = environmentService.userDataPath; this.uninstalledFileLimiter = new Limiter(1); this.disposables.push(toDisposable(() => this.installingExtensions.clear())); + + this.reportedPath = path.join(this.extensionsPath, '.reported'); + this.reportedExtensions = this.loadReportFromCache(); + + setTimeout(() => this.loopRefreshReportCache(), 1000 * 10); // 10 seconds after boot } private deleteExtensionsManifestCache(): void { - const cacheFolder = path.join(this.userDataPath, MANIFEST_CACHE_FOLDER); + const cacheFolder = path.join(this.environmentService.userDataPath, MANIFEST_CACHE_FOLDER); const cacheFile = path.join(cacheFolder, USER_MANIFEST_CACHE_FILE); pfs.del(cacheFile).done(() => { }, () => { }); @@ -776,6 +782,48 @@ export class ExtensionManagementService implements IExtensionManagementService { }); } + getExtensionsReport(): TPromise { + return this.reportedExtensions; + } + + private loadReportFromCache(): TPromise { + this.logService.trace('ExtensionManagementService.loadReportedFromCache'); + + return pfs.readFile(this.reportedPath, 'utf8') + .then(raw => JSON.parse(raw)) + .then(result => { + this.logService.trace(`ExtensionManagementService.loadReportedFromCache - loaded ${result.length} reported extensions from cache`); + return result; + }, () => { + this.logService.trace(`ExtensionManagementService.loadReportedFromCache - no cache found`); + }); + } + + private loopRefreshReportCache(): void { + this.refreshReportCache() + .then(() => TPromise.timeout(1000 * 60 * 5)) // every five minutes + .then(() => this.loopRefreshReportCache()); + } + + private refreshReportCache(): TPromise { + this.logService.trace('ExtensionManagementService.refreshReportedCache'); + + return this.reportedExtensions = this.galleryService.getExtensionsReport() + .then(null, err => { + this.logService.trace('ExtensionManagementService.refreshReportedCache - failed to get extension report'); + return []; + }) + .then(result => { + this.logService.trace(`ExtensionManagementService.refreshReportedCache - got ${result.length} reported extensions from service`); + + return pfs.writeFile(this.reportedPath, JSON.stringify(result)) + .then(() => result, err => { + this.logService.trace('ExtensionManagementService.refreshReportedCache - failed to cache extension report'); + return result; + }); + }); + } + dispose() { this.disposables = dispose(this.disposables); } -- GitLab