Merge pull request #2233 from mempool/nymkappa/bugfix/missing-alias-fallback-pubkey

Set default values when pubkey, capacity and channels are missing from top nodes
This commit is contained in:
wiz 2022-08-01 17:50:37 +00:00 committed by GitHub
commit c4f125b2d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,7 +66,15 @@ class NodesApi {
public async $getTopCapacityNodes(): Promise<any> {
try {
const query = `SELECT nodes.*, node_stats.capacity, node_stats.channels FROM nodes LEFT JOIN node_stats ON node_stats.public_key = nodes.public_key ORDER BY node_stats.added DESC, node_stats.capacity DESC LIMIT 10`;
const query = `
SELECT IF(nodes.alias = '', SUBSTRING(nodes.public_key, 1, 20), alias) as alias, nodes.public_key,
CAST(COALESCE(node_stats.capacity, 0) as INT) as capacity,
CAST(COALESCE(node_stats.channels, 0) as INT) as channels
FROM nodes
LEFT JOIN node_stats ON node_stats.public_key = nodes.public_key
ORDER BY node_stats.added DESC, node_stats.capacity DESC
LIMIT 10
`;
const [rows]: any = await DB.query(query);
return rows;
} catch (e) {
@ -77,7 +85,15 @@ class NodesApi {
public async $getTopChannelsNodes(): Promise<any> {
try {
const query = `SELECT nodes.*, node_stats.capacity, node_stats.channels FROM nodes LEFT JOIN node_stats ON node_stats.public_key = nodes.public_key ORDER BY node_stats.added DESC, node_stats.channels DESC LIMIT 10`;
const query = `
SELECT IF(nodes.alias = '', SUBSTRING(nodes.public_key, 1, 20), alias) as alias, nodes.public_key,
CAST(COALESCE(node_stats.capacity, 0) as INT) as capacity,
CAST(COALESCE(node_stats.channels, 0) as INT) as channels
FROM nodes
LEFT JOIN node_stats
ON node_stats.public_key = nodes.public_key
ORDER BY node_stats.added DESC, node_stats.channels DESC
LIMIT 10`;
const [rows]: any = await DB.query(query);
return rows;
} catch (e) {