Merge pull request #2470 from mempool/nymkappa/bugfix/node-update
Consider channels updates as well for node updated at field
This commit is contained in:
commit
e65d2a522f
@ -522,6 +522,23 @@ class ChannelsApi {
|
|||||||
logger.err('$setChannelsInactive() error: ' + (e instanceof Error ? e.message : e));
|
logger.err('$setChannelsInactive() error: ' + (e instanceof Error ? e.message : e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async $getLatestChannelUpdateForNode(publicKey: string): Promise<number> {
|
||||||
|
try {
|
||||||
|
const query = `
|
||||||
|
SELECT MAX(UNIX_TIMESTAMP(updated_at)) as updated_at
|
||||||
|
FROM channels
|
||||||
|
WHERE node1_public_key = ?
|
||||||
|
`;
|
||||||
|
const [rows]: any[] = await DB.query(query, [publicKey]);
|
||||||
|
if (rows.length > 0) {
|
||||||
|
return rows[0].updated_at;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.err(`Can't getLatestChannelUpdateForNode for ${publicKey}. Reason ${e instanceof Error ? e.message : e}`);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new ChannelsApi();
|
export default new ChannelsApi();
|
||||||
|
@ -63,6 +63,9 @@ class NetworkSyncService {
|
|||||||
let deletedSockets = 0;
|
let deletedSockets = 0;
|
||||||
const graphNodesPubkeys: string[] = [];
|
const graphNodesPubkeys: string[] = [];
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
|
const latestUpdated = await channelsApi.$getLatestChannelUpdateForNode(node.pub_key);
|
||||||
|
node.last_update = Math.max(node.last_update, latestUpdated);
|
||||||
|
|
||||||
await nodesApi.$saveNode(node);
|
await nodesApi.$saveNode(node);
|
||||||
graphNodesPubkeys.push(node.pub_key);
|
graphNodesPubkeys.push(node.pub_key);
|
||||||
++progress;
|
++progress;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user