Rewrite queries to get top nodes by channels and capacity
This commit is contained in:
parent
55966e601a
commit
82cef095fc
@ -66,16 +66,19 @@ class NodesApi {
|
|||||||
|
|
||||||
public async $getTopCapacityNodes(): Promise<any> {
|
public async $getTopCapacityNodes(): Promise<any> {
|
||||||
try {
|
try {
|
||||||
|
let [rows]: any[] = await DB.query('SELECT UNIX_TIMESTAMP(MAX(added)) as maxAdded FROM node_stats');
|
||||||
|
const latestDate = rows[0].maxAdded;
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
SELECT IF(nodes.alias = '', SUBSTRING(nodes.public_key, 1, 20), alias) as alias, nodes.public_key,
|
SELECT nodes.public_key, nodes.alias, node_stats.capacity, node_stats.channels
|
||||||
CAST(COALESCE(node_stats.capacity, 0) as INT) as capacity,
|
FROM node_stats
|
||||||
CAST(COALESCE(node_stats.channels, 0) as INT) as channels
|
JOIN nodes ON nodes.public_key = node_stats.public_key
|
||||||
FROM nodes
|
WHERE added = FROM_UNIXTIME(${latestDate})
|
||||||
LEFT JOIN node_stats ON node_stats.public_key = nodes.public_key
|
ORDER BY capacity DESC
|
||||||
ORDER BY node_stats.added DESC, node_stats.capacity DESC
|
LIMIT 10;
|
||||||
LIMIT 10
|
|
||||||
`;
|
`;
|
||||||
const [rows]: any = await DB.query(query);
|
[rows] = await DB.query(query);
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.err('$getTopCapacityNodes error: ' + (e instanceof Error ? e.message : e));
|
logger.err('$getTopCapacityNodes error: ' + (e instanceof Error ? e.message : e));
|
||||||
@ -85,16 +88,19 @@ class NodesApi {
|
|||||||
|
|
||||||
public async $getTopChannelsNodes(): Promise<any> {
|
public async $getTopChannelsNodes(): Promise<any> {
|
||||||
try {
|
try {
|
||||||
|
let [rows]: any[] = await DB.query('SELECT UNIX_TIMESTAMP(MAX(added)) as maxAdded FROM node_stats');
|
||||||
|
const latestDate = rows[0].maxAdded;
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
SELECT IF(nodes.alias = '', SUBSTRING(nodes.public_key, 1, 20), alias) as alias, nodes.public_key,
|
SELECT nodes.public_key, nodes.alias, node_stats.capacity, node_stats.channels
|
||||||
CAST(COALESCE(node_stats.capacity, 0) as INT) as capacity,
|
FROM node_stats
|
||||||
CAST(COALESCE(node_stats.channels, 0) as INT) as channels
|
JOIN nodes ON nodes.public_key = node_stats.public_key
|
||||||
FROM nodes
|
WHERE added = FROM_UNIXTIME(${latestDate})
|
||||||
LEFT JOIN node_stats
|
ORDER BY channels DESC
|
||||||
ON node_stats.public_key = nodes.public_key
|
LIMIT 10;
|
||||||
ORDER BY node_stats.added DESC, node_stats.channels DESC
|
`;
|
||||||
LIMIT 10`;
|
[rows] = await DB.query(query);
|
||||||
const [rows]: any = await DB.query(query);
|
|
||||||
return rows;
|
return rows;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.err('$getTopChannelsNodes error: ' + (e instanceof Error ? e.message : e));
|
logger.err('$getTopChannelsNodes error: ' + (e instanceof Error ? e.message : e));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user