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

Method applyNewChanges

packages/core/src/engine/engine.ts:325–366  ·  view source on GitHub ↗
(cs: IRemoteChangeset)

Source from the content-addressed store, hash-verified

323 }
324
325 private applyNewChanges(cs: IRemoteChangeset) {
326 // Receive newChanges from itself. This happens because the client disconnects and reconnects,
327 // and the reconnected client is considered a collaborator.
328 // At this time, the changeset sent by yourself will be broadcast to yourself as newChanges again.
329 // So we have to first judge the equality of messageId
330 // If messageId is equal, it is regarded as ACK.
331 if (this.bufferStorage.localPendingChangeset && cs.messageId === this.bufferStorage.localPendingChangeset.messageId) {
332 console.error('messageId in newChanges is equal to localChangeset and has been converted to ACK');
333 void this.handleAcceptCommit(cs);
334 return;
335 }
336
337 const revision = this.getRevision();
338 // must ensure that data.revision does not jump carry
339 if (cs.revision > revision + 1) {
340 console.log('revision error', revision, cs.revision);
341 throw new Error('miss changes didn\'t well prepared');
342 }
343
344 // Changesets smaller than the current version are ignored directly
345 if (cs.revision <= revision) {
346 console.warn('older changeset received and ignored');
347 return;
348 }
349
350 if (revision == null || cs.revision !== +revision + 1) {
351 console.error('currentRevision', revision, cs);
352 throw new Error('wrong changeset revision');
353 }
354
355 const nextRevision = +revision + 1;
356
357 const remoteActions = this.doTransform(cs);
358
359 const _remoteActions = this.viewPropertyFilter ? this.viewPropertyFilter.parseActions(remoteActions, { fromServer: true }) : remoteActions;
360
361 this.dispatch(updateRevision(nextRevision, this.resourceId, this.resourceType));
362
363 this.event.onNewChanges(this.resourceType, this.resourceId, _remoteActions);
364
365 return _remoteActions;
366 }
367
368 // Check the missing version of the remote changeset, and if there is one, directly fill in the missing changeset and apply it to the snapshot.
369 async checkMissChanges(revisionUpgradeTo: number) {

Callers 2

handleNewChangesMethod · 0.95
checkMissChangesMethod · 0.95

Calls 10

handleAcceptCommitMethod · 0.95
doTransformMethod · 0.95
updateRevisionFunction · 0.90
warnMethod · 0.80
parseActionsMethod · 0.80
errorMethod · 0.65
onNewChangesMethod · 0.65
getRevisionMethod · 0.45
logMethod · 0.45
dispatchMethod · 0.45

Tested by

no test coverage detected