From 4335ee815716d286609f1638a020286ce32ec359 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Mon, 1 Aug 2022 18:41:31 +0200 Subject: [PATCH] Set default values when pubkey, capacity and channels are missing from top nodes --- backend/src/api/explorer/nodes.api.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/src/api/explorer/nodes.api.ts b/backend/src/api/explorer/nodes.api.ts index f05c4cf0a..4c7028136 100644 --- a/backend/src/api/explorer/nodes.api.ts +++ b/backend/src/api/explorer/nodes.api.ts @@ -66,7 +66,15 @@ class NodesApi { public async $getTopCapacityNodes(): Promise { 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 { 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) {