MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / SplitBackendUpdate

Function SplitBackendUpdate

pkg/vdom/vdom_root.go:618–671  ·  view source on GitHub ↗

SplitBackendUpdate splits a large VDomBackendUpdate into multiple smaller updates The first update contains all the core fields, while subsequent updates only contain array elements that need to be appended

(update *VDomBackendUpdate)

Source from the content-addressed store, hash-verified

616// The first update contains all the core fields, while subsequent updates only contain
617// array elements that need to be appended
618func SplitBackendUpdate(update *VDomBackendUpdate) []*VDomBackendUpdate {
619 // If the update is small enough, return it as is
620 if len(update.TransferElems) <= BackendUpdate_InitialChunkSize && len(update.StateSync) <= BackendUpdate_InitialChunkSize {
621 return []*VDomBackendUpdate{update}
622 }
623
624 var updates []*VDomBackendUpdate
625
626 // First update contains core fields and initial chunks
627 firstUpdate := &VDomBackendUpdate{
628 Type: update.Type,
629 Ts: update.Ts,
630 BlockId: update.BlockId,
631 Opts: update.Opts,
632 HasWork: update.HasWork,
633 RenderUpdates: update.RenderUpdates,
634 RefOperations: update.RefOperations,
635 Messages: update.Messages,
636 }
637
638 // Add initial chunks of arrays
639 if len(update.TransferElems) > 0 {
640 firstUpdate.TransferElems = update.TransferElems[:min(BackendUpdate_InitialChunkSize, len(update.TransferElems))]
641 }
642 if len(update.StateSync) > 0 {
643 firstUpdate.StateSync = update.StateSync[:min(BackendUpdate_InitialChunkSize, len(update.StateSync))]
644 }
645
646 updates = append(updates, firstUpdate)
647
648 // Create subsequent updates for remaining TransferElems
649 for i := BackendUpdate_InitialChunkSize; i < len(update.TransferElems); i += BackendUpdate_ChunkSize {
650 end := min(i+BackendUpdate_ChunkSize, len(update.TransferElems))
651 updates = append(updates, &VDomBackendUpdate{
652 Type: update.Type,
653 Ts: update.Ts,
654 BlockId: update.BlockId,
655 TransferElems: update.TransferElems[i:end],
656 })
657 }
658
659 // Create subsequent updates for remaining StateSync
660 for i := BackendUpdate_InitialChunkSize; i < len(update.StateSync); i += BackendUpdate_ChunkSize {
661 end := min(i+BackendUpdate_ChunkSize, len(update.StateSync))
662 updates = append(updates, &VDomBackendUpdate{
663 Type: update.Type,
664 Ts: update.Ts,
665 BlockId: update.BlockId,
666 StateSync: update.StateSync[i:end],
667 })
668 }
669
670 return updates
671}

Callers 1

VDomRenderCommandMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected