Update node sockets during historical import so we don't have to truncate

This commit is contained in:
nymkappa 2022-08-29 09:01:07 +02:00
parent f25ec08f5e
commit 0847e15d07
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04
2 changed files with 14 additions and 0 deletions

View File

@ -503,6 +503,18 @@ class NodesApi {
}
}
/**
* Update node sockets
*/
public async $updateNodeSockets(publicKey: string, sockets: {network: string; addr: string}[]): Promise<void> {
const formattedSockets = (sockets.map(a => a.addr).join(',')) ?? '';
try {
await DB.query(`UPDATE nodes SET sockets = ? WHERE public_key = ?`, [formattedSockets, publicKey]);
} catch (e) {
logger.err(`Cannot update node sockets for ${publicKey}. Reason: ${e instanceof Error ? e.message : e}`);
}
}
/**
* Set all nodes not in `nodesPubkeys` as inactive (status = 0)
*/

View File

@ -51,6 +51,8 @@ class LightningStatsImporter {
features: node.features,
});
nodesInDb[node.pub_key] = node;
} else {
await nodesApi.$updateNodeSockets(node.pub_key, node.addresses);
}
let hasOnion = false;