mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-11 14:48:14 +01:00
graph/db+sqldb: delete channels in batches
Use the new `SLICES` directive to add a DeleteChannels query which takes a set of DB channel IDs. Then replace all our calls to DeleteChannel with a paginated call to DeleteChannels.
This commit is contained in:
@@ -143,15 +143,6 @@ func (q *Queries) CreateChannelExtraType(ctx context.Context, arg CreateChannelE
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteChannel = `-- name: DeleteChannel :exec
|
||||
DELETE FROM graph_channels WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteChannel(ctx context.Context, id int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteChannel, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteChannelPolicyExtraTypes = `-- name: DeleteChannelPolicyExtraTypes :exec
|
||||
DELETE FROM graph_channel_policy_extra_types
|
||||
WHERE channel_policy_id = $1
|
||||
@@ -162,6 +153,26 @@ func (q *Queries) DeleteChannelPolicyExtraTypes(ctx context.Context, channelPoli
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteChannels = `-- name: DeleteChannels :exec
|
||||
DELETE FROM graph_channels
|
||||
WHERE id IN (/*SLICE:ids*/?)
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteChannels(ctx context.Context, ids []int64) error {
|
||||
query := deleteChannels
|
||||
var queryParams []interface{}
|
||||
if len(ids) > 0 {
|
||||
for _, v := range ids {
|
||||
queryParams = append(queryParams, v)
|
||||
}
|
||||
query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
|
||||
} else {
|
||||
query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
|
||||
}
|
||||
_, err := q.db.ExecContext(ctx, query, queryParams...)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
|
||||
DELETE FROM graph_node_extra_types
|
||||
WHERE node_id = $1
|
||||
|
||||
Reference in New Issue
Block a user