store neighbour info directly in the nodes table

This commit is contained in:
liamcottle
2024-03-23 22:56:03 +13:00
parent 22dceaac54
commit d7252c9962
3 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE `nodes` ADD COLUMN `neighbour_broadcast_interval_secs` INTEGER NULL,
ADD COLUMN `neighbours` JSON NULL;

View File

@ -31,6 +31,9 @@ model Node {
channel_utilization Decimal? channel_utilization Decimal?
air_util_tx Decimal? air_util_tx Decimal?
neighbour_broadcast_interval_secs Int?
neighbours Json?
created_at DateTime @default(now()) created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt updated_at DateTime @default(now()) @updatedAt

View File

@ -273,6 +273,7 @@ client.on("message", async (topic, message) => {
}); });
} }
// create neighbour info
try { try {
await prisma.neighbourInfo.create({ await prisma.neighbourInfo.create({
data: { data: {
@ -290,6 +291,26 @@ client.on("message", async (topic, message) => {
console.error(e); console.error(e);
} }
// update node neighbour info in db
try {
await prisma.node.updateMany({
where: {
node_id: envelope.packet.from,
},
data: {
neighbour_broadcast_interval_secs: neighbourInfo.nodeBroadcastIntervalSecs,
neighbours: neighbourInfo.neighbors.map((neighbour) => {
return {
node_id: neighbour.nodeId,
snr: neighbour.snr,
};
}),
},
});
} catch (e) {
console.error(e);
}
} }
else if(portnum === 67) { else if(portnum === 67) {