Skip to content

Commit

Permalink
fix: reverted getTransactions to 3.8.2 version for performance reasons (
Browse files Browse the repository at this point in the history
  • Loading branch information
ohager authored Dec 22, 2024
1 parent 4df3b2d commit 158f770
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/brs/db/sql/SqlBlockchainStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ public long getAtBurnTotal() {

@Override
public Collection<Transaction> getTransactions(Account account, int numberOfConfirmations, byte type, byte subtype, int blockTimestamp, int from, int to, boolean includeIndirectIncoming) {

// note to devs: this method does not scale. as of 12, 2024 some account suffer long loading times here. some unsuccessful trials to refactor the queries failed. So, touch this method only
// if you are really understand what you are doing.
int height = getHeightForNumberOfConfirmations(numberOfConfirmations);
return Db.useDSLContext(ctx -> {
ArrayList<Condition> conditions = new ArrayList<>();

if (blockTimestamp > 0) {
conditions.add(TRANSACTION.BLOCK_TIMESTAMP.ge(blockTimestamp));
}
Expand All @@ -170,26 +170,26 @@ public Collection<Transaction> getTransactions(Account account, int numberOfConf
conditions.add(TRANSACTION.HEIGHT.le(height));
}

Condition accountCondition = DSL.trueCondition();
if (account != null) {
accountCondition = TRANSACTION.RECIPIENT_ID.eq(account.getId())
.and(TRANSACTION.SENDER_ID.ne(account.getId()))
.or(TRANSACTION.SENDER_ID.eq(account.getId()));
SelectOrderByStep<TransactionRecord> select = ctx.selectFrom(TRANSACTION).where(conditions).and(
account == null ? TRANSACTION.RECIPIENT_ID.isNull() :
TRANSACTION.RECIPIENT_ID.eq(account.getId()).and(
TRANSACTION.SENDER_ID.ne(account.getId())
)
).unionAll(
account == null ? null :
ctx.selectFrom(TRANSACTION).where(conditions).and(
TRANSACTION.SENDER_ID.eq(account.getId())
)
);

if (includeIndirectIncoming) {
accountCondition = accountCondition.or(
TRANSACTION.ID.in(
DSL.select(INDIRECT_INCOMING.TRANSACTION_ID)
.from(INDIRECT_INCOMING)
.where(INDIRECT_INCOMING.ACCOUNT_ID.eq(account.getId()))
)
);
}
if (includeIndirectIncoming) {
select = select.unionAll(ctx.selectFrom(TRANSACTION)
.where(conditions)
.and(TRANSACTION.ID.in(ctx.select(INDIRECT_INCOMING.TRANSACTION_ID).from(INDIRECT_INCOMING)
.where(INDIRECT_INCOMING.ACCOUNT_ID.eq(account.getId())))));
}

SelectQuery<TransactionRecord> selectQuery = ctx.selectFrom(TRANSACTION)
.where(conditions)
.and(accountCondition)
SelectQuery<TransactionRecord> selectQuery = select
.orderBy(TRANSACTION.BLOCK_TIMESTAMP.desc(), TRANSACTION.ID.desc())
.getQuery();

Expand Down

0 comments on commit 158f770

Please sign in to comment.