graph/db: use batch loading for ChanUpdatesInHorizon

The following performance gains were measured using the new benchmark
test.

```
name                                      old time/op  new time/op  delta
ChanUpdatesInHorizon-native-sqlite-10     18.5s ± 3%    2.0s ± 5%  -89.11%  (p=0.000 n=9+9)
ChanUpdatesInHorizon-native-postgres-10   59.0s ± 3%    0.8s ±10%  -98.65%  (p=0.000 n=10+9)
```
This commit is contained in:
Elle Mouton
2025-08-05 12:08:26 +02:00
parent ce3401ee5d
commit ebe6a8af9f
2 changed files with 193 additions and 51 deletions

View File

@@ -37,3 +37,37 @@ func makeQueryParams(numTotalArgs, numListArgs int) string {
return b.String()
}
// ChannelAndNodes is an interface that provides access to a channel and its
// two nodes.
type ChannelAndNodes interface {
// Channel returns the GraphChannel associated with this interface.
Channel() GraphChannel
// Node1 returns the first GraphNode associated with this channel.
Node1() GraphNode
// Node2 returns the second GraphNode associated with this channel.
Node2() GraphNode
}
// Channel returns the GraphChannel associated with this interface.
//
// NOTE: This method is part of the ChannelAndNodes interface.
func (r GetChannelsByPolicyLastUpdateRangeRow) Channel() GraphChannel {
return r.GraphChannel
}
// Node1 returns the first GraphNode associated with this channel.
//
// NOTE: This method is part of the ChannelAndNodes interface.
func (r GetChannelsByPolicyLastUpdateRangeRow) Node1() GraphNode {
return r.GraphNode
}
// Node2 returns the second GraphNode associated with this channel.
//
// NOTE: This method is part of the ChannelAndNodes interface.
func (r GetChannelsByPolicyLastUpdateRangeRow) Node2() GraphNode {
return r.GraphNode_2
}