MCPcopy Create free account
hub / github.com/instantdb/instant / onSyncLoadBatch

Method onSyncLoadBatch

client/packages/core/src/SyncTable.ts:639–692  ·  view source on GitHub ↗
(msg: SyncLoadBatchMsg)

Source from the content-addressed store, hash-verified

637 }
638
639 public onSyncLoadBatch(msg: SyncLoadBatchMsg) {
640 const subscriptionId = msg['subscription-id'];
641 const joinRows = msg['join-rows'];
642 const hash = this.idToHash[subscriptionId];
643 if (!hash) {
644 this.log.error('Missing hash for subscription', msg);
645 return;
646 }
647
648 const batch: any[] = [];
649 const sub = this.subs.currentValue[hash];
650 if (!sub) {
651 this.log.error('Missing sub for hash', hash, msg);
652 return;
653 }
654
655 const values: SubValues = sub.values ?? {
656 entities: [],
657 attrsStore: this.getAttrs(),
658 };
659 sub.values = values;
660 const entities = values.entities;
661
662 for (const entRows of joinRows) {
663 const store = this.createStore(entRows);
664 const entity = queryEntity(sub, store, values.attrsStore);
665 entities.push({
666 store,
667 entity,
668 serverCreatedAt: getServerCreatedAt(
669 sub,
670 store,
671 values.attrsStore,
672 entity.id,
673 ),
674 });
675 batch.push(entity);
676 }
677
678 this.subs.updateInPlace((prev) => {
679 prev[hash] = sub;
680 // Make sure we write a field or mutative won't
681 // see the change because sub === prev[hash]
682 prev[hash].updatedAt = Date.now();
683 });
684
685 if (sub.values) {
686 this.notifyCbs(hash, {
687 type: CallbackEventType.InitialSyncBatch,
688 data: subData(sub, sub.values.entities),
689 batch,
690 });
691 }
692 }
693
694 public onSyncInitFinish(msg: SyncInitFinishMsg) {
695 const subscriptionId = msg['subscription-id'];

Callers 1

_handleReceiveMethod · 0.80

Calls 7

notifyCbsMethod · 0.95
queryEntityFunction · 0.85
getServerCreatedAtFunction · 0.85
subDataFunction · 0.85
pushMethod · 0.80
updateInPlaceMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected