Merge pull request #2654 from mempool/nymkappa/bugfix/node-count
Only show active nodes is isp page
This commit is contained in:
commit
37bf67aa38
@ -524,7 +524,37 @@ class NodesApi {
|
|||||||
|
|
||||||
public async $getNodesPerISP(ISPId: string) {
|
public async $getNodesPerISP(ISPId: string) {
|
||||||
try {
|
try {
|
||||||
const query = `
|
let query = `
|
||||||
|
SELECT channels.node1_public_key AS node1PublicKey, isp1.id as isp1ID,
|
||||||
|
channels.node2_public_key AS node2PublicKey, isp2.id as isp2ID
|
||||||
|
FROM channels
|
||||||
|
JOIN nodes node1 ON node1.public_key = channels.node1_public_key
|
||||||
|
JOIN nodes node2 ON node2.public_key = channels.node2_public_key
|
||||||
|
JOIN geo_names isp1 ON isp1.id = node1.as_number
|
||||||
|
JOIN geo_names isp2 ON isp2.id = node2.as_number
|
||||||
|
WHERE channels.status = 1 AND (node1.as_number IN (?) OR node2.as_number IN (?))
|
||||||
|
ORDER BY short_id DESC
|
||||||
|
`;
|
||||||
|
|
||||||
|
const IPSIds = ISPId.split(',');
|
||||||
|
const [rows]: any = await DB.query(query, [IPSIds, IPSIds]);
|
||||||
|
const nodes = {};
|
||||||
|
|
||||||
|
const intISPIds: number[] = [];
|
||||||
|
for (const ispId of IPSIds) {
|
||||||
|
intISPIds.push(parseInt(ispId, 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const channel of rows) {
|
||||||
|
if (intISPIds.includes(channel.isp1ID)) {
|
||||||
|
nodes[channel.node1PublicKey] = true;
|
||||||
|
}
|
||||||
|
if (intISPIds.includes(channel.isp2ID)) {
|
||||||
|
nodes[channel.node2PublicKey] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query = `
|
||||||
SELECT nodes.public_key, CAST(COALESCE(nodes.capacity, 0) as INT) as capacity, CAST(COALESCE(nodes.channels, 0) as INT) as channels,
|
SELECT nodes.public_key, CAST(COALESCE(nodes.capacity, 0) as INT) as capacity, CAST(COALESCE(nodes.channels, 0) as INT) as channels,
|
||||||
nodes.alias, UNIX_TIMESTAMP(nodes.first_seen) as first_seen, UNIX_TIMESTAMP(nodes.updated_at) as updated_at,
|
nodes.alias, UNIX_TIMESTAMP(nodes.first_seen) as first_seen, UNIX_TIMESTAMP(nodes.updated_at) as updated_at,
|
||||||
geo_names_city.names as city, geo_names_country.names as country,
|
geo_names_city.names as city, geo_names_country.names as country,
|
||||||
@ -535,17 +565,18 @@ class NodesApi {
|
|||||||
LEFT JOIN geo_names geo_names_city ON geo_names_city.id = nodes.city_id AND geo_names_city.type = 'city'
|
LEFT JOIN geo_names geo_names_city ON geo_names_city.id = nodes.city_id AND geo_names_city.type = 'city'
|
||||||
LEFT JOIN geo_names geo_names_iso ON geo_names_iso.id = nodes.country_id AND geo_names_iso.type = 'country_iso_code'
|
LEFT JOIN geo_names geo_names_iso ON geo_names_iso.id = nodes.country_id AND geo_names_iso.type = 'country_iso_code'
|
||||||
LEFT JOIN geo_names geo_names_subdivision on geo_names_subdivision.id = nodes.subdivision_id AND geo_names_subdivision.type = 'division'
|
LEFT JOIN geo_names geo_names_subdivision on geo_names_subdivision.id = nodes.subdivision_id AND geo_names_subdivision.type = 'division'
|
||||||
WHERE nodes.as_number IN (?)
|
WHERE nodes.public_key IN (?)
|
||||||
ORDER BY capacity DESC
|
ORDER BY capacity DESC
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const [rows]: any = await DB.query(query, [ISPId.split(',')]);
|
const [rows2]: any = await DB.query(query, [Object.keys(nodes)]);
|
||||||
for (let i = 0; i < rows.length; ++i) {
|
for (let i = 0; i < rows2.length; ++i) {
|
||||||
rows[i].country = JSON.parse(rows[i].country);
|
rows2[i].country = JSON.parse(rows2[i].country);
|
||||||
rows[i].city = JSON.parse(rows[i].city);
|
rows2[i].city = JSON.parse(rows2[i].city);
|
||||||
rows[i].subdivision = JSON.parse(rows[i].subdivision);
|
rows2[i].subdivision = JSON.parse(rows2[i].subdivision);
|
||||||
}
|
}
|
||||||
return rows;
|
return rows2;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.err(`Cannot get nodes for ISP id ${ISPId}. Reason: ${e instanceof Error ? e.message : e}`);
|
logger.err(`Cannot get nodes for ISP id ${ISPId}. Reason: ${e instanceof Error ? e.message : e}`);
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<td>{{ isp?.id }}</td>
|
<td>{{ isp?.id }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td i18n="lightning.node-count">Nodes</td>
|
<td i18n="lightning.active-node-count">Active nodes</td>
|
||||||
<td>{{ ispNodes.nodes.length }}</td>
|
<td>{{ ispNodes.nodes.length }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user