Skip to content

Commit 16a4527

Browse files
committed
handle empty topologies
1 parent e857bb4 commit 16a4527

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/repository/NodeRepository.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,18 @@ export class NodeRepository {
130130
}
131131
}
132132
}
133+
logger.info('Replace network topology:', { nodeCount: nodes.length, neighborCount: neighbors.length })
133134
const connection = await this.connectionPool.getConnection()
134135
try {
135136
await connection.beginTransaction()
136137
await connection.query('DELETE FROM neighbors')
137138
await connection.query('DELETE FROM nodes')
138-
await connection.query('INSERT INTO nodes (id, ipAddress) VALUES ?', [nodes])
139-
await connection.query('INSERT INTO neighbors (streamPartId, nodeId1, nodeId2, rtt) VALUES ?', [neighbors])
139+
if (nodes.length > 0) {
140+
await connection.query('INSERT INTO nodes (id, ipAddress) VALUES ?', [nodes])
141+
}
142+
if (neighbors.length > 0) {
143+
await connection.query('INSERT INTO neighbors (streamPartId, nodeId1, nodeId2, rtt) VALUES ?', [neighbors])
144+
}
140145
await connection.commit()
141146
} catch (e) {
142147
connection.rollback()

0 commit comments

Comments
 (0)