提交 d536410f 编写于 作者: J Joao Moreno

extension report cache and load

上级 d14d66d1
......@@ -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<void>;
uninstall(extension: ILocalExtension, force?: boolean): TPromise<void>;
getInstalled(type?: LocalExtensionType): TPromise<ILocalExtension[]>;
getExtensionsReport(): TPromise<IReportedExtension[]>;
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension>;
}
......
......@@ -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<void>;
call(command: 'uninstall', args: [ILocalExtension, boolean]): TPromise<void>;
call(command: 'getInstalled'): TPromise<ILocalExtension[]>;
call(command: 'getExtensionsReport'): TPromise<IReportedExtension[]>;
call(command: string, arg?: any): TPromise<any>;
}
......@@ -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<ILocalExtension> {
return this.channel.call('updateMetadata', [local, metadata]);
}
getExtensionsReport(): TPromise<IReportedExtension[]> {
return this.channel.call('getExtensionsReport');
}
}
\ No newline at end of file
......@@ -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));
});
});
......
......@@ -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<void>;
private reportedExtensions: TPromise<IReportedExtension[]>;
private disposables: IDisposable[] = [];
private readonly _onInstallExtension = new Emitter<InstallExtensionEvent>();
......@@ -122,20 +124,24 @@ export class ExtensionManagementService implements IExtensionManagementService {
onDidUninstallExtension: Event<DidUninstallExtensionEvent> = 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<IReportedExtension[]> {
return this.reportedExtensions;
}
private loadReportFromCache(): TPromise<IReportedExtension[]> {
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<any> {
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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册