sqldb+graph/db: prune graph nodes in a single query
Update the pruneGraphNodes routine to prune the graph nodes in a single query instead of two.
This commit is contained in:
4 files changed
+65
-81
No files matched your search
@@ -65,21 +65,21 @@ SELECT EXISTS (
|
||||
AND n.pub_key = $1
|
||||
);
|
||||
|
||||
-- name: GetUnconnectedNodes :many
|
||||
SELECT n.id, n.pub_key
|
||||
FROM nodes n
|
||||
-- Select all nodes that do not have any channels.
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM channels c
|
||||
WHERE c.node_id_1 = n.id OR c.node_id_2 = n.id
|
||||
)
|
||||
-- Ignore any of our source nodes.
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM source_nodes sn
|
||||
WHERE sn.node_id = n.id
|
||||
);
|
||||
-- name: DeleteUnconnectedNodes :many
|
||||
DELETE FROM nodes
|
||||
WHERE
|
||||
-- Ignore any of our source nodes.
|
||||
NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM source_nodes sn
|
||||
WHERE sn.node_id = nodes.id
|
||||
)
|
||||
-- Select all nodes that do not have any channels.
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM channels c
|
||||
WHERE c.node_id_1 = nodes.id OR c.node_id_2 = nodes.id
|
||||
) RETURNING pub_key;
|
||||
|
||||
-- name: DeleteNodeByPubKey :execresult
|
||||
DELETE FROM nodes
|
||||
|
||||
Reference in new issue
Block a user