From 6a6f0cf79902c699cf3cead25fcda77fc7fd8a2a Mon Sep 17 00:00:00 2001 From: Theodore Schnepper Date: Thu, 23 May 2024 07:21:18 -0600 Subject: [PATCH] Fix explorer summary histogram data order The histogram data returned by the `get_explorer_summary` endpoint is returned in the wrong order. The data is meant to be in the order of ascending block height, but it is returned in descending block height order. This is due to the way we retrieve the last 50 blocks. To fix this the query that retrieves the latest 50 blocks is changed slightly. Using a sub-query, we can target the last 50 blocks, then re-sort the rows based on the block height ascending to get the correct ordering. --- src/data_source/storage/sql.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/data_source/storage/sql.rs b/src/data_source/storage/sql.rs index baad6550d..73d65a448 100644 --- a/src/data_source/storage/sql.rs +++ b/src/data_source/storage/sql.rs @@ -2219,8 +2219,10 @@ where FROM header AS h JOIN payload AS p ON p.height = h.height - ORDER BY h.height DESC - LIMIT 50", + WHERE + h.height IN (SELECT height FROM header ORDER BY height DESC LIMIT 50) + ORDER BY h.height ASC + ", Vec::>::new(), ).await?;