graph/db: batch loading for DisconnectBlockAtHeight

This commit is contained in:
Elle Mouton
2025-08-05 14:09:43 +02:00
parent 69bcf47dca
commit 594c842aeb
2 changed files with 41 additions and 18 deletions

View File

@@ -2627,27 +2627,29 @@ func (s *SQLStore) DisconnectBlockAtHeight(height uint32) (
return fmt.Errorf("unable to fetch channels: %w", err)
}
chanIDsToDelete := make([]int64, len(rows))
for i, row := range rows {
node1, node2, err := buildNodeVertices(
row.Node1PubKey, row.Node2PubKey,
if len(rows) == 0 {
// No channels to disconnect, but still clean up prune
// log.
return db.DeletePruneLogEntriesInRange(
ctx, sqlc.DeletePruneLogEntriesInRangeParams{
StartHeight: int64(height),
EndHeight: int64(
endShortChanID.BlockHeight,
),
},
)
if err != nil {
return err
}
channel, err := getAndBuildEdgeInfo(
ctx, db, s.cfg.ChainHash, row.GraphChannel,
node1, node2,
)
if err != nil {
return err
}
chanIDsToDelete[i] = row.GraphChannel.ID
removedChans = append(removedChans, channel)
}
// Batch build all channel edges for disconnection.
channelEdges, chanIDsToDelete, err := batchBuildChannelInfo(
ctx, s.cfg, db, rows,
)
if err != nil {
return err
}
removedChans = channelEdges
err = s.deleteChannels(ctx, db, chanIDsToDelete)
if err != nil {
return fmt.Errorf("unable to delete channels: %w", err)