Merge pull request #2381 from mempool/nymkappa/bugfix/useless-mysql-query-channel-tree
Do not fetch node stats for channel tree graph
This commit is contained in:
		
						commit
						144eb558c4
					
				| @ -288,21 +288,36 @@ class ChannelsApi { | |||||||
| 
 | 
 | ||||||
|       const channels: any[] = [] |       const channels: any[] = [] | ||||||
|       for (const row of allChannels) { |       for (const row of allChannels) { | ||||||
|         const activeChannelsStats: any = await nodesApi.$getActiveChannelsStats(row.public_key); |         let channel; | ||||||
|         channels.push({ |         if (index >= 0) { | ||||||
|           status: row.status, |           const activeChannelsStats: any = await nodesApi.$getActiveChannelsStats(row.public_key); | ||||||
|           closing_reason: row.closing_reason, |           channel = { | ||||||
|           capacity: row.capacity ?? 0, |             status: row.status, | ||||||
|           short_id: row.short_id, |             closing_reason: row.closing_reason, | ||||||
|           id: row.id, |             capacity: row.capacity ?? 0, | ||||||
|           fee_rate: row.node1_fee_rate ?? row.node2_fee_rate ?? 0, |             short_id: row.short_id, | ||||||
|           node: { |             id: row.id, | ||||||
|             alias: row.alias.length > 0 ? row.alias : row.public_key.slice(0, 20), |             fee_rate: row.node1_fee_rate ?? row.node2_fee_rate ?? 0, | ||||||
|             public_key: row.public_key, |             node: { | ||||||
|             channels: activeChannelsStats.active_channel_count ?? 0, |               alias: row.alias.length > 0 ? row.alias : row.public_key.slice(0, 20), | ||||||
|             capacity: activeChannelsStats.capacity ?? 0, |               public_key: row.public_key, | ||||||
|           } |               channels: activeChannelsStats.active_channel_count ?? 0, | ||||||
|         }); |               capacity: activeChannelsStats.capacity ?? 0, | ||||||
|  |             } | ||||||
|  |           }; | ||||||
|  |         } else if (index === -1) { | ||||||
|  |           channel = { | ||||||
|  |             capacity: row.capacity ?? 0, | ||||||
|  |             short_id: row.short_id, | ||||||
|  |             id: row.id, | ||||||
|  |             node: { | ||||||
|  |               alias: row.alias.length > 0 ? row.alias : row.public_key.slice(0, 20), | ||||||
|  |               public_key: row.public_key, | ||||||
|  |             } | ||||||
|  |           }; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         channels.push(channel); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       return channels; |       return channels; | ||||||
|  | |||||||
| @ -47,8 +47,17 @@ class ChannelsRoutes { | |||||||
|         res.status(400).send('Missing parameter: public_key'); |         res.status(400).send('Missing parameter: public_key'); | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|  | 
 | ||||||
|       const index = parseInt(typeof req.query.index === 'string' ? req.query.index : '0', 10) || 0; |       const index = parseInt(typeof req.query.index === 'string' ? req.query.index : '0', 10) || 0; | ||||||
|       const status: string = typeof req.query.status === 'string' ? req.query.status : ''; |       const status: string = typeof req.query.status === 'string' ? req.query.status : ''; | ||||||
|  | 
 | ||||||
|  |       if (index < -1) { | ||||||
|  |         res.status(400).send('Invalid index'); | ||||||
|  |       } | ||||||
|  |       if (['open', 'active', 'closed'].includes(status) === false) { | ||||||
|  |         res.status(400).send('Invalid status'); | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|       const channels = await channelsApi.$getChannelsForNode(req.query.public_key, index, 10, status); |       const channels = await channelsApi.$getChannelsForNode(req.query.public_key, index, 10, status); | ||||||
|       const channelsCount = await channelsApi.$getChannelsCountForNode(req.query.public_key, status); |       const channelsCount = await channelsApi.$getChannelsCountForNode(req.query.public_key, status); | ||||||
|       res.header('Pragma', 'public'); |       res.header('Pragma', 'public'); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user