提交 7f3f074d 编写于 作者: S Sandeep Somavarapu

fix merging

上级 e149709f
......@@ -53,19 +53,19 @@ export function merge(localStorage: IStringDictionary<IStorageValue>, remoteStor
}
}
// Updated in Remote
for (const key of values(baseToRemote.updated)) {
// Updated in local
for (const key of values(baseToLocal.updated)) {
if (!baseToRemote.updated.has(key) || !baseToRemote.removed.has(key)) {
const remoteValue = remote[key];
const localValue = localStorage[key];
if (localValue.version >= remoteValue.version) {
remote[key] = remoteValue;
remote[key] = localValue;
}
}
}
// Removed in remote
for (const key of values(baseToRemote.removed)) {
// Removed in local
for (const key of values(baseToLocal.removed)) {
if (!baseToRemote.updated.has(key)) {
const remoteValue = remote[key];
const storageKey = storageKeys.filter(storageKey => storageKey.key === key)[0];
......@@ -75,7 +75,7 @@ export function merge(localStorage: IStringDictionary<IStorageValue>, remoteStor
}
}
return { local, remote: areSame(remote, remoteStorage) ? null : remoteStorage };
return { local, remote: areSame(remote, remoteStorage) ? null : remote };
}
function compare(from: IStringDictionary<any>, to: IStringDictionary<any>): { added: Set<string>, removed: Set<string>, updated: Set<string> } {
......
......@@ -163,7 +163,7 @@ export class GlobalStateSynchroniser extends AbstractSynchroniser implements IUs
private async getPreview(remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null): Promise<ISyncPreviewResult> {
const remoteGlobalState: IGlobalState = remoteUserData.syncData ? JSON.parse(remoteUserData.syncData.content) : null;
const lastSyncGlobalState = lastSyncUserData && lastSyncUserData.syncData ? JSON.parse(lastSyncUserData.syncData.content) : null;
const lastSyncGlobalState: IGlobalState = lastSyncUserData && lastSyncUserData.syncData ? JSON.parse(lastSyncUserData.syncData.content) : null;
const localGloablState = await this.getLocalGlobalState();
......@@ -173,7 +173,7 @@ export class GlobalStateSynchroniser extends AbstractSynchroniser implements IUs
this.logService.trace(`${this.syncResourceLogLabel}: Remote ui state does not exist. Synchronizing ui state for the first time.`);
}
const { local, remote } = merge(localGloablState.storage, remoteGlobalState.storage, lastSyncGlobalState, this.storageKeysSyncRegistryService.storageKeys);
const { local, remote } = merge(localGloablState.storage, remoteGlobalState.storage, lastSyncGlobalState ? lastSyncGlobalState.storage : null, this.storageKeysSyncRegistryService.storageKeys);
return { local, remote, remoteUserData, localUserData: localGloablState, lastSyncUserData };
}
......@@ -198,7 +198,7 @@ export class GlobalStateSynchroniser extends AbstractSynchroniser implements IUs
if (hasRemoteChanged) {
// update remote
this.logService.trace(`${this.syncResourceLogLabel}: Updating remote ui state...`);
const content = JSON.stringify(remote);
const content = JSON.stringify(<IGlobalState>{ storage: remote });
remoteUserData = await this.updateRemoteUserData(content, forcePush ? null : remoteUserData.ref);
this.logService.info(`${this.syncResourceLogLabel}: Updated remote ui state`);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册