MCPcopy
hub / github.com/wavetermdev/waveterm / deleteBlockObj

Function deleteBlockObj

pkg/wcore/block.go:194–233  ·  view source on GitHub ↗

returns the updated block count for the parent object

(ctx context.Context, blockId string)

Source from the content-addressed store, hash-verified

192
193// returns the updated block count for the parent object
194func deleteBlockObj(ctx context.Context, blockId string) (int, error) {
195 return wstore.WithTxRtn(ctx, func(tx *wstore.TxWrap) (int, error) {
196 block, err := wstore.DBGet[*waveobj.Block](tx.Context(), blockId)
197 if err != nil {
198 return -1, fmt.Errorf("error getting block: %w", err)
199 }
200 if block == nil {
201 return -1, fmt.Errorf("block not found: %q", blockId)
202 }
203 if len(block.SubBlockIds) > 0 {
204 return -1, fmt.Errorf("block has subblocks, must delete subblocks first")
205 }
206 parentORef := waveobj.ParseORefNoErr(block.ParentORef)
207 parentBlockCount := -1
208 if parentORef != nil {
209 if parentORef.OType == waveobj.OType_Tab {
210 tab, _ := wstore.DBGet[*waveobj.Tab](tx.Context(), parentORef.OID)
211 if tab != nil {
212 tab.BlockIds = utilfn.RemoveElemFromSlice(tab.BlockIds, blockId)
213 wstore.DBUpdate(tx.Context(), tab)
214 parentBlockCount = len(tab.BlockIds)
215 }
216 } else if parentORef.OType == waveobj.OType_Block {
217 parentBlock, _ := wstore.DBGet[*waveobj.Block](tx.Context(), parentORef.OID)
218 if parentBlock != nil {
219 parentBlock.SubBlockIds = utilfn.RemoveElemFromSlice(parentBlock.SubBlockIds, blockId)
220 wstore.DBUpdate(tx.Context(), parentBlock)
221 parentBlockCount = len(parentBlock.SubBlockIds)
222 }
223 }
224 }
225 wstore.DBDelete(tx.Context(), waveobj.OType_Block, blockId)
226
227 // Clean up block runtime info
228 blockORef := waveobj.MakeORef(waveobj.OType_Block, blockId)
229 wstore.DeleteRTInfo(blockORef)
230
231 return parentBlockCount, nil
232 })
233}
234
235func sendBlockCloseEvent(blockId string) {
236 waveEvent := wps.WaveEvent{

Callers 2

CreateBlockWithTelemetryFunction · 0.85
DeleteBlockFunction · 0.85

Calls 9

WithTxRtnFunction · 0.92
DBGetFunction · 0.92
ParseORefNoErrFunction · 0.92
RemoveElemFromSliceFunction · 0.92
DBUpdateFunction · 0.92
DBDeleteFunction · 0.92
MakeORefFunction · 0.92
DeleteRTInfoFunction · 0.92
ContextMethod · 0.45

Tested by

no test coverage detected