mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-19 12:01:27 +02:00
graph/db+sqldb: use batch validation for closed SCID migration
As was done in the previous commits for nodes & channels, we update the migrateClosedSCIDIndex function here so that it validates migrated entries in batches rather than one-by-one.
This commit is contained in:
@@ -1602,6 +1602,45 @@ func (q *Queries) GetChannelsBySCIDs(ctx context.Context, arg GetChannelsBySCIDs
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getClosedChannelsSCIDs = `-- name: GetClosedChannelsSCIDs :many
|
||||
SELECT scid
|
||||
FROM graph_closed_scids
|
||||
WHERE scid IN (/*SLICE:scids*/?)
|
||||
`
|
||||
|
||||
func (q *Queries) GetClosedChannelsSCIDs(ctx context.Context, scids [][]byte) ([][]byte, error) {
|
||||
query := getClosedChannelsSCIDs
|
||||
var queryParams []interface{}
|
||||
if len(scids) > 0 {
|
||||
for _, v := range scids {
|
||||
queryParams = append(queryParams, v)
|
||||
}
|
||||
query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(scids)), 1)
|
||||
} else {
|
||||
query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
|
||||
}
|
||||
rows, err := q.db.QueryContext(ctx, query, queryParams...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items [][]byte
|
||||
for rows.Next() {
|
||||
var scid []byte
|
||||
if err := rows.Scan(&scid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, scid)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
|
||||
SELECT node_id, type, value
|
||||
FROM graph_node_extra_types
|
||||
|
@@ -48,6 +48,7 @@ type Querier interface {
|
||||
GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error)
|
||||
GetChannelsBySCIDWithPolicies(ctx context.Context, arg GetChannelsBySCIDWithPoliciesParams) ([]GetChannelsBySCIDWithPoliciesRow, error)
|
||||
GetChannelsBySCIDs(ctx context.Context, arg GetChannelsBySCIDsParams) ([]GraphChannel, error)
|
||||
GetClosedChannelsSCIDs(ctx context.Context, scids [][]byte) ([][]byte, error)
|
||||
GetDatabaseVersion(ctx context.Context) (int32, error)
|
||||
GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]GraphNodeExtraType, error)
|
||||
// This method may return more than one invoice if filter using multiple fields
|
||||
|
@@ -984,3 +984,8 @@ SELECT EXISTS (
|
||||
FROM graph_closed_scids
|
||||
WHERE scid = $1
|
||||
);
|
||||
|
||||
-- name: GetClosedChannelsSCIDs :many
|
||||
SELECT scid
|
||||
FROM graph_closed_scids
|
||||
WHERE scid IN (sqlc.slice('scids')/*SLICE:scids*/);
|
||||
|
Reference in New Issue
Block a user