forked from Qortal/qortal
Speed-ups for some AT-related SQL queries
This commit is contained in:
parent
1cd4bbc078
commit
f1efae79c8
@ -76,7 +76,7 @@ public class TradeOffersWebSocket extends ApiWebSocket implements Listener {
|
|||||||
List<CrossChainOfferSummary> crossChainOfferSummaries;
|
List<CrossChainOfferSummary> crossChainOfferSummaries;
|
||||||
|
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
// Find any new trade ATs since this block
|
// Find any new/changed trade ATs since this block
|
||||||
final Boolean isFinished = null;
|
final Boolean isFinished = null;
|
||||||
final Integer dataByteOffset = null;
|
final Integer dataByteOffset = null;
|
||||||
final Long expectedValue = null;
|
final Long expectedValue = null;
|
||||||
|
@ -10,6 +10,8 @@ import org.qortal.data.at.ATStateData;
|
|||||||
import org.qortal.repository.ATRepository;
|
import org.qortal.repository.ATRepository;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
|
|
||||||
public class HSQLDBATRepository implements ATRepository {
|
public class HSQLDBATRepository implements ATRepository {
|
||||||
|
|
||||||
protected HSQLDBRepository repository;
|
protected HSQLDBRepository repository;
|
||||||
@ -298,8 +300,14 @@ public class HSQLDBATRepository implements ATRepository {
|
|||||||
+ "CROSS JOIN LATERAL("
|
+ "CROSS JOIN LATERAL("
|
||||||
+ "SELECT height, created_when, state_data, state_hash, fees, is_initial "
|
+ "SELECT height, created_when, state_data, state_hash, fees, is_initial "
|
||||||
+ "FROM ATStates "
|
+ "FROM ATStates "
|
||||||
+ "WHERE ATStates.AT_address = ATs.AT_address "
|
+ "WHERE ATStates.AT_address = ATs.AT_address ");
|
||||||
+ "ORDER BY height DESC "
|
|
||||||
|
if (minimumFinalHeight != null) {
|
||||||
|
sql.append("AND height >= ");
|
||||||
|
sql.append(minimumFinalHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
sql.append( "ORDER BY height DESC "
|
||||||
+ "LIMIT 1 "
|
+ "LIMIT 1 "
|
||||||
+ ") AS FinalATStates "
|
+ ") AS FinalATStates "
|
||||||
+ "WHERE code_hash = ? ");
|
+ "WHERE code_hash = ? ");
|
||||||
@ -313,19 +321,14 @@ public class HSQLDBATRepository implements ATRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dataByteOffset != null && expectedValue != null) {
|
if (dataByteOffset != null && expectedValue != null) {
|
||||||
sql.append("AND RAWTOHEX(SUBSTRING(state_data FROM ? FOR 8)) = ? ");
|
sql.append("AND SUBSTRING(state_data FROM ? FOR 8) = ? ");
|
||||||
|
|
||||||
// We convert our long to hex Java-side to control endian
|
// We convert our long on Java-side to control endian
|
||||||
String expectedHexValue = String.format("%016x", expectedValue); // left-zero-padding and conversion
|
byte[] rawExpectedValue = Longs.toByteArray(expectedValue);
|
||||||
|
|
||||||
// SQL binary data offsets start at 1
|
// SQL binary data offsets start at 1
|
||||||
bindParams.add(dataByteOffset + 1);
|
bindParams.add(dataByteOffset + 1);
|
||||||
bindParams.add(expectedHexValue);
|
bindParams.add(rawExpectedValue);
|
||||||
}
|
|
||||||
|
|
||||||
if (minimumFinalHeight != null) {
|
|
||||||
sql.append("AND height >= ");
|
|
||||||
sql.append(minimumFinalHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.append(" ORDER BY height ");
|
sql.append(" ORDER BY height ");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user