Save latest node channel update in node.updated_at field in db
This commit is contained in:
		
							parent
							
								
									9131521e7d
								
							
						
					
					
						commit
						ff1aae853e
					
				@ -522,6 +522,23 @@ class ChannelsApi {
 | 
			
		||||
      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();
 | 
			
		||||
 | 
			
		||||
@ -63,6 +63,9 @@ class NetworkSyncService {
 | 
			
		||||
    let deletedSockets = 0;
 | 
			
		||||
    const graphNodesPubkeys: string[] = [];
 | 
			
		||||
    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);
 | 
			
		||||
      graphNodesPubkeys.push(node.pub_key);
 | 
			
		||||
      ++progress;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user