mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-19 12:01:27 +02: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
|
||||
|
@@ -18,8 +18,8 @@ type Querier interface {
|
||||
CreateChannel(ctx context.Context, arg CreateChannelParams) (int64, error)
|
||||
CreateChannelExtraType(ctx context.Context, arg CreateChannelExtraTypeParams) error
|
||||
DeleteCanceledInvoices(ctx context.Context) (sql.Result, error)
|
||||
DeleteChannel(ctx context.Context, id int64) error
|
||||
DeleteChannelPolicyExtraTypes(ctx context.Context, channelPolicyID int64) error
|
||||
DeleteChannels(ctx context.Context, ids []int64) error
|
||||
DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error
|
||||
DeleteInvoice(ctx context.Context, arg DeleteInvoiceParams) (sql.Result, error)
|
||||
DeleteNode(ctx context.Context, id int64) error
|
||||
|
@@ -569,8 +569,9 @@ WHERE c.version = $1 AND c.id > $2
|
||||
ORDER BY c.id
|
||||
LIMIT $3;
|
||||
|
||||
-- name: DeleteChannel :exec
|
||||
DELETE FROM graph_channels WHERE id = $1;
|
||||
-- name: DeleteChannels :exec
|
||||
DELETE FROM graph_channels
|
||||
WHERE id IN (sqlc.slice('ids')/*SLICE:ids*/);
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
graph_channel_features table queries
|
||||
|
Reference in New Issue
Block a user