MCPcopy Create free account
hub / github.com/apitable/apitable / checkLocalDiffChanges

Method checkLocalDiffChanges

packages/core/src/engine/engine.ts:391–436  ·  view source on GitHub ↗
(checkVersion?: number)

Source from the content-addressed store, hash-verified

389 // Check the version gap between the local snapshot and the local changeset.
390 // If there is a gap, transform and rebase the localChangeset.
391 async checkLocalDiffChanges(checkVersion?: number) {
392 if (!this.bufferStorage.localPendingChangeset) {
393 checkVersion != null && this.checkMissChanges(checkVersion);
394 return;
395 }
396
397 Player.doTrigger(Events.app_error_logger, {
398 error: new Error(t(Strings.error_an_unsynchronized_changeset_is_detected)),
399 metaData: this.bufferStorage.localPendingChangeset,
400 });
401 const revision = this.getRevision();
402 const baseRevision = this.bufferStorage.localPendingChangeset.baseRevision;
403
404 if (baseRevision > revision) {
405 throw new Error('localRevision greater than remoteRevision');
406 }
407
408 console.log('checkLocalDiffChanges: ', { baseRevision, revision });
409
410 if (baseRevision < revision) {
411 let changesetList = await this.fetchMissVersion(baseRevision + 1, revision + 1);
412 /**
413 * Check if localChangeset is already in changesetList, if so
414 * 1. It means that localChangeset has been applied to the snapshot, so it does not need to be sent locally
415 * 2. This changeset before this needs to be transformed, and the latter does not need to be transformed
416 */
417 const transformEndIndex = changesetList.findIndex(changeset => {
418 return changeset.messageId === this.bufferStorage.localPendingChangeset!.messageId;
419 });
420
421 changesetList = changesetList.slice(0, transformEndIndex);
422
423 if (transformEndIndex >= 0) {
424 // 1. Discard localChangeset.
425 // 2. opBuffer becomes the new localChangeset, and baseRevision is set to the revision
426 // in the changesetList where the original localChangeset is located.
427 console.log('Detected that the local localPendingChangeset has been consumed, delete it directly', this.bufferStorage.localPendingChangeset);
428 this.bufferStorage.deOpBuffer(revision);
429 console.log('The local opBuffer enters localPendingChangeset', this.bufferStorage.localPendingChangeset);
430 }
431
432 changesetList.forEach(changeset => {
433 this.doTransform(changeset);
434 });
435 }
436 }
437
438 private doTransform(cs: IRemoteChangeset) {
439 let remoteActions = cs.operations.reduce<IJOTAction[]>((pre, op) => {

Callers 1

prepareMethod · 0.95

Calls 9

checkMissChangesMethod · 0.95
fetchMissVersionMethod · 0.95
doTransformMethod · 0.95
tFunction · 0.90
findIndexMethod · 0.80
deOpBufferMethod · 0.80
getRevisionMethod · 0.45
logMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected