mirror of
https://github.com/tcivie/meshtastic-metrics-exporter.git
synced 2025-02-02 07:41:11 -08:00
Merge pull request #21 from tcivie/add-support-for-neighbour-info
Add support for neighbour info
This commit is contained in:
commit
ced7f47cc9
|
@ -45,10 +45,8 @@ CREATE TABLE IF NOT EXISTS node_neighbors
|
|||
neighbor_id VARCHAR,
|
||||
snr FLOAT,
|
||||
FOREIGN KEY (node_id) REFERENCES client_details (node_id),
|
||||
FOREIGN KEY (neighbor_id) REFERENCES node_graph (node_id),
|
||||
FOREIGN KEY (neighbor_id) REFERENCES client_details (node_id),
|
||||
UNIQUE (node_id, neighbor_id)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_node_neighbors_node_id ON node_neighbors (node_id);
|
||||
CREATE INDEX idx_node_neighbors_neighbor_id ON node_neighbors (neighbor_id);
|
||||
CREATE UNIQUE INDEX idx_unique_node_neighbor ON node_neighbors (node_id, neighbor_id);
|
||||
|
|
|
@ -504,11 +504,21 @@ class NeighborInfoAppProcessor(Processor):
|
|||
|
||||
for neighbor in neighbor_info.neighbors:
|
||||
cur.execute("""
|
||||
INSERT INTO node_neighbors (node_id, neighbor_id, snr)
|
||||
VALUES (%s, %s, %s)
|
||||
ON CONFLICT (node_id, neighbor_id)
|
||||
DO UPDATE SET snr = EXCLUDED.snr
|
||||
""", (client_details.node_id, str(neighbor.node_id), float(neighbor.snr)))
|
||||
WITH upsert AS (
|
||||
INSERT INTO node_neighbors (node_id, neighbor_id, snr)
|
||||
VALUES (%s, %s, %s)
|
||||
ON CONFLICT (node_id, neighbor_id)
|
||||
DO UPDATE SET snr = EXCLUDED.snr
|
||||
RETURNING node_id, neighbor_id
|
||||
)
|
||||
INSERT INTO client_details (node_id)
|
||||
SELECT node_id FROM upsert
|
||||
WHERE NOT EXISTS (SELECT 1 FROM client_details WHERE node_id = upsert.node_id)
|
||||
UNION
|
||||
SELECT neighbor_id FROM upsert
|
||||
WHERE NOT EXISTS (SELECT 1 FROM client_details WHERE node_id = upsert.neighbor_id)
|
||||
ON CONFLICT (node_id) DO NOTHING;
|
||||
""", (str(client_details.node_id), str(neighbor.node_id), float(neighbor.snr)))
|
||||
|
||||
conn.commit()
|
||||
|
||||
|
|
Loading…
Reference in a new issue