From ce3401ee5d7450829f20866ecae6e49a0ebb04fd Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 5 Aug 2025 13:53:40 +0200 Subject: [PATCH] graph/db: refactor buildNode to not take a pointer Since the type returned from the DB is not a pointer. This will be useful later on. --- graph/db/sql_migration.go | 2 +- graph/db/sql_store.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/graph/db/sql_migration.go b/graph/db/sql_migration.go index e1ff256a2..8a529765b 100644 --- a/graph/db/sql_migration.go +++ b/graph/db/sql_migration.go @@ -192,7 +192,7 @@ func migrateNodes(ctx context.Context, kvBackend kvdb.Backend, pub, id, dbNode.ID) } - migratedNode, err := buildNode(ctx, sqlDB, &dbNode) + migratedNode, err := buildNode(ctx, sqlDB, dbNode) if err != nil { return fmt.Errorf("could not build migrated node "+ "from dbNode(db id: %d, node pub: %x): %w", diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index c991c3b30..95b4ad2ad 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -3231,7 +3231,7 @@ func getNodeByPubKey(ctx context.Context, db SQLQueries, return 0, nil, fmt.Errorf("unable to fetch node: %w", err) } - node, err := buildNode(ctx, db, &dbNode) + node, err := buildNode(ctx, db, dbNode) if err != nil { return 0, nil, fmt.Errorf("unable to build node: %w", err) } @@ -3256,7 +3256,7 @@ func buildCacheableChannelInfo(scid []byte, capacity int64, node1Pub, // record. The node's features, addresses and extra signed fields are also // fetched from the database and set on the node. func buildNode(ctx context.Context, db SQLQueries, - dbNode *sqlc.GraphNode) (*models.LightningNode, error) { + dbNode sqlc.GraphNode) (*models.LightningNode, error) { // NOTE: buildNode is only used to load the data for a single node, and // so no paged queries will be performed. This means that it's ok to @@ -3276,7 +3276,7 @@ func buildNode(ctx context.Context, db SQLQueries, // from the provided sqlc.GraphNode and batchNodeData. If the node does have // features/addresses/extra fields, then the corresponding fields are expected // to be present in the batchNodeData. -func buildNodeWithBatchData(dbNode *sqlc.GraphNode, +func buildNodeWithBatchData(dbNode sqlc.GraphNode, batchData *batchNodeData) (*models.LightningNode, error) { if dbNode.Version != int16(ProtocolV1) { @@ -3364,7 +3364,7 @@ func forEachNodeInBatch(ctx context.Context, cfg *sqldb.QueryConfig, } for _, dbNode := range nodes { - node, err := buildNodeWithBatchData(&dbNode, batchData) + node, err := buildNodeWithBatchData(dbNode, batchData) if err != nil { return fmt.Errorf("unable to build node(id=%d): %w", dbNode.ID, err) @@ -4235,12 +4235,12 @@ func buildNodes(ctx context.Context, db SQLQueries, dbNode1, dbNode2 sqlc.GraphNode) (*models.LightningNode, *models.LightningNode, error) { - node1, err := buildNode(ctx, db, &dbNode1) + node1, err := buildNode(ctx, db, dbNode1) if err != nil { return nil, nil, err } - node2, err := buildNode(ctx, db, &dbNode2) + node2, err := buildNode(ctx, db, dbNode2) if err != nil { return nil, nil, err } @@ -5090,7 +5090,7 @@ func forEachNodePaginated(ctx context.Context, cfg *sqldb.QueryConfig, processItem := func(ctx context.Context, dbNode sqlc.GraphNode, batchData *batchNodeData) error { - node, err := buildNodeWithBatchData(&dbNode, batchData) + node, err := buildNodeWithBatchData(dbNode, batchData) if err != nil { return fmt.Errorf("unable to build "+ "node(id=%d): %w", dbNode.ID, err)