From 158f770164f8c0b03d9a4dd74832bed01c303bd9 Mon Sep 17 00:00:00 2001 From: ohager Date: Sun, 22 Dec 2024 19:56:16 -0300 Subject: [PATCH] fix: reverted getTransactions to 3.8.2 version for performance reasons (#849) --- src/brs/db/sql/SqlBlockchainStore.java | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/brs/db/sql/SqlBlockchainStore.java b/src/brs/db/sql/SqlBlockchainStore.java index 7c26a3f84..40e791a1d 100644 --- a/src/brs/db/sql/SqlBlockchainStore.java +++ b/src/brs/db/sql/SqlBlockchainStore.java @@ -152,11 +152,11 @@ public long getAtBurnTotal() { @Override public Collection 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 conditions = new ArrayList<>(); - if (blockTimestamp > 0) { conditions.add(TRANSACTION.BLOCK_TIMESTAMP.ge(blockTimestamp)); } @@ -170,26 +170,26 @@ public Collection 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 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 selectQuery = ctx.selectFrom(TRANSACTION) - .where(conditions) - .and(accountCondition) + SelectQuery selectQuery = select .orderBy(TRANSACTION.BLOCK_TIMESTAMP.desc(), TRANSACTION.ID.desc()) .getQuery();