提交 1eb2a37e 编写于 作者: S Sandeep Somavarapu

do not sync extension state when extension has not registered any keys to sync

上级 20601293
...@@ -74,10 +74,14 @@ export function merge(localExtensions: ISyncExtension[], remoteExtensions: ISync ...@@ -74,10 +74,14 @@ export function merge(localExtensions: ISyncExtension[], remoteExtensions: ISync
const baseToRemote = compare(lastSyncExtensionsMap, remoteExtensionsMap, ignoredExtensionsSet); const baseToRemote = compare(lastSyncExtensionsMap, remoteExtensionsMap, ignoredExtensionsSet);
const mergeAndUpdate = (key: string): void => { const mergeAndUpdate = (key: string): void => {
const extension = remoteExtensionsMap.get(key)!; const localExtension = localExtensionsMap.get(key)!;
extension.state = mergeExtensionState(localExtensionsMap.get(key)?.state, extension.state, lastSyncExtensionsMap?.get(key)?.state); const remoteExtension = remoteExtensionsMap.get(key)!;
updated.push(massageOutgoingExtension(extension, key)); // merge extension state only when version matches and local extension has state
newRemoteExtensionsMap.set(key, extension); if (remoteExtension.version === localExtension.version && localExtension.state) {
remoteExtension.state = mergeExtensionState(localExtension.state, remoteExtension.state, lastSyncExtensionsMap?.get(key)?.state);
}
updated.push(massageOutgoingExtension(remoteExtension, key));
newRemoteExtensionsMap.set(key, remoteExtension);
}; };
// Remotely removed extension. // Remotely removed extension.
...@@ -183,18 +187,7 @@ function compare(from: Map<string, ISyncExtension> | null, to: Map<string, ISync ...@@ -183,18 +187,7 @@ function compare(from: Map<string, ISyncExtension> | null, to: Map<string, ISync
return { added, removed, updated }; return { added, removed, updated };
} }
function mergeExtensionState(local: IStringDictionary<any> | undefined, remote: IStringDictionary<any> | undefined, base: IStringDictionary<any> | undefined): IStringDictionary<any> | undefined { function mergeExtensionState(local: IStringDictionary<any>, remote: IStringDictionary<any> | undefined, base: IStringDictionary<any> | undefined): IStringDictionary<any> | undefined {
if (!local && !remote && !base) {
return undefined;
}
if (local && !remote && !base) {
return local;
}
if (remote && !local && !base) {
return remote;
}
local = local || {};
const merged: IStringDictionary<any> = deepClone(local); const merged: IStringDictionary<any> = deepClone(local);
if (remote) { if (remote) {
const baseToRemote = base ? compareExtensionState(base, remote) : { added: Object.keys(remote).reduce((r, k) => { r.add(k); return r; }, new Set<string>()), removed: new Set<string>(), updated: new Set<string>() }; const baseToRemote = base ? compareExtensionState(base, remote) : { added: Object.keys(remote).reduce((r, k) => { r.add(k); return r; }, new Set<string>()), removed: new Set<string>(), updated: new Set<string>() };
......
...@@ -450,14 +450,14 @@ export class ExtensionsSynchroniser extends AbstractSynchroniser implements IUse ...@@ -450,14 +450,14 @@ export class ExtensionsSynchroniser extends AbstractSynchroniser implements IUse
syncExntesion.installed = true; syncExntesion.installed = true;
} }
const keys = this.storageKeysSyncRegistryService.getExtensioStorageKeys({ id: identifier.id, version: manifest.version }); const keys = this.storageKeysSyncRegistryService.getExtensioStorageKeys({ id: identifier.id, version: manifest.version });
if (keys) {
const extensionStorageValue = this.storageService.get(identifier.id, StorageScope.GLOBAL) || '{}';
try { try {
const extensionStorageValue = this.storageService.get(identifier.id, StorageScope.GLOBAL); syncExntesion.state = JSON.parse(extensionStorageValue, (key, value) => !key || keys.includes(key) ? value : undefined);
syncExntesion.state = keys.length && extensionStorageValue
? JSON.parse(extensionStorageValue, (key, value) => !key || keys.includes(key) ? value : undefined)
: undefined;
} catch (error) { } catch (error) {
this.logService.info(`${this.syncResourceLogLabel}: Error while parsing extension state`, getErrorMessage(error)); this.logService.info(`${this.syncResourceLogLabel}: Error while parsing extension state`, getErrorMessage(error));
} }
}
return syncExntesion; return syncExntesion;
}); });
} }
......
...@@ -76,7 +76,7 @@ export interface IStorageKeysSyncRegistryService { ...@@ -76,7 +76,7 @@ export interface IStorageKeysSyncRegistryService {
/** /**
* Returns storage keys of the given extension that has to be synchronized. * Returns storage keys of the given extension that has to be synchronized.
*/ */
getExtensioStorageKeys(extension: IExtensionIdWithVersion): ReadonlyArray<string>; getExtensioStorageKeys(extension: IExtensionIdWithVersion): ReadonlyArray<string> | undefined;
} }
export abstract class AbstractStorageKeysSyncRegistryService extends Disposable implements IStorageKeysSyncRegistryService { export abstract class AbstractStorageKeysSyncRegistryService extends Disposable implements IStorageKeysSyncRegistryService {
...@@ -103,8 +103,8 @@ export abstract class AbstractStorageKeysSyncRegistryService extends Disposable ...@@ -103,8 +103,8 @@ export abstract class AbstractStorageKeysSyncRegistryService extends Disposable
this._register(toDisposable(() => this._storageKeys.clear())); this._register(toDisposable(() => this._storageKeys.clear()));
} }
getExtensioStorageKeys(extension: IExtensionIdWithVersion): ReadonlyArray<string> { getExtensioStorageKeys(extension: IExtensionIdWithVersion): ReadonlyArray<string> | undefined {
return this._extensionsStorageKeys.get(ExtensionIdWithVersion.toKey(extension)) || []; return this._extensionsStorageKeys.get(ExtensionIdWithVersion.toKey(extension));
} }
protected updateExtensionStorageKeys(extension: IExtensionIdWithVersion, keys: string[]): void { protected updateExtensionStorageKeys(extension: IExtensionIdWithVersion, keys: string[]): void {
......
...@@ -731,7 +731,7 @@ class SimpleIStorageKeysSyncRegistryService implements IStorageKeysSyncRegistryS ...@@ -731,7 +731,7 @@ class SimpleIStorageKeysSyncRegistryService implements IStorageKeysSyncRegistryS
extensionsStorageKeys = []; extensionsStorageKeys = [];
getExtensioStorageKeys(): [] { return []; } getExtensioStorageKeys() { return undefined; }
registerExtensionStorageKeys(): void { } registerExtensionStorageKeys(): void { }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册