graph/db+sqldb: improve efficiency of node migration

There is no need to use the "collect-then-update" pattern for node
insertion during the SQL migration since if we do have any previously
persisted data for the node and happen to re-run the insertion for that
node, the data will be exactly the same. So we can make use of "On
conflict, no nothing" here too.
This commit is contained in:
Elle Mouton
2025-08-15 09:43:40 +02:00
parent ddea6d59ce
commit a291d6f1a6
5 changed files with 129 additions and 79 deletions

View File

@@ -105,7 +105,9 @@ INSERT INTO graph_node_features (
node_id, feature_bit
) VALUES (
$1, $2
);
) ON CONFLICT (node_id, feature_bit)
-- Do nothing if the feature already exists for the node.
DO NOTHING;
-- name: GetNodeFeatures :many
SELECT *
@@ -135,7 +137,7 @@ WHERE node_id = $1
───────────────────────────────────<E29480><E29480>─────────
*/
-- name: InsertNodeAddress :exec
-- name: UpsertNodeAddress :exec
INSERT INTO graph_node_addresses (
node_id,
type,
@@ -143,7 +145,8 @@ INSERT INTO graph_node_addresses (
position
) VALUES (
$1, $2, $3, $4
);
) ON CONFLICT (node_id, type, position)
DO UPDATE SET address = EXCLUDED.address;
-- name: GetNodeAddresses :many
SELECT type, address