Speed up fetching block height based on timestamp

This commit is contained in:
catbref 2020-09-11 15:55:54 +01:00
parent 8a1e2f4111
commit c628f97d8c

View File

@ -120,7 +120,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
@Override
public int getHeightFromTimestamp(long timestamp) throws DataException {
// Uses (minted_when, height) index
String sql = "SELECT height FROM Blocks WHERE minted_when <= ? ORDER BY minted_when DESC LIMIT 1";
String sql = "SELECT height FROM Blocks WHERE minted_when <= ? ORDER BY minted_when DESC, height DESC LIMIT 1";
try (ResultSet resultSet = this.repository.checkedExecute(sql, timestamp)) {
if (resultSet == null)