Skip to content

Conversation

@0xbigapple
Copy link
Owner

What does this PR do?
Optimization postLogsFilter function, If the block result is already in memory, use it directly. Avoids re-querying the database for data just written.

Why are these changes required?

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

@0xbigapple 0xbigapple closed this Jan 20, 2026
@0xbigapple 0xbigapple reopened this Jan 20, 2026
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This pull request introduces a valuable performance optimization to the postLogsFilter method by checking for in-memory block results before querying the database. The logic is sound and improves efficiency.

🔍 General Feedback

  • The core change is a good optimization that avoids unnecessary database lookups.
  • A critical typo was found in a method call that will need to be fixed for the build to pass.

Once the typo is addressed, this change will be a solid improvement.

= getTransactionInfoByBlockNum(blockNumber).getTransactionInfoList();
List<TransactionInfo> transactionInfoList;
// Optimization: If the block result is already in memory, use it directly.
// Avoids re-querying the database for data just written.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 There's a typo in the method name getTransactioninfoList. Based on Java conventions and likely protobuf generated code, it should be getTransactionInfoList with a capital 'I'. This will cause a compilation error.

Suggested change
// Avoids re-querying the database for data just written.
transactionInfoList = blockCapsule.getResult().getInstance().getTransactionInfoList();

@0xbigapple 0xbigapple closed this Jan 20, 2026
@0xbigapple 0xbigapple reopened this Jan 20, 2026
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

## 📋 Review Summary

This pull request introduces a valuable performance optimization to the postLogsFilter function. By checking for transaction information in memory before querying the database, it avoids unnecessary database operations, which should improve performance. The implementation is clear and correct.

🔍 General Feedback

  • The change is well-contained and directly addresses the goal of the optimization.
  • The use of a fallback mechanism ensures that the existing functionality is preserved if the in-memory data is not available.
  • A minor suggestion was made to improve code cleanliness by removing a redundant comment.

Overall, this is a good improvement.

Comment on lines +2275 to +2281
// Avoids re-querying the database for data just written.
if (blockCapsule.getResult() != null) {
transactionInfoList = blockCapsule.getResult().getInstance().getTransactioninfoList();
} else {
// Fallback to querying from DB if not available in memory.
transactionInfoList = getTransactionInfoByBlockNum(blockNumber).getTransactionInfoList();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 The comment in the `else` block is redundant because the code is self-explanatory. Consider removing it to make the code cleaner.
Suggested change
// Avoids re-querying the database for data just written.
if (blockCapsule.getResult() != null) {
transactionInfoList = blockCapsule.getResult().getInstance().getTransactioninfoList();
} else {
// Fallback to querying from DB if not available in memory.
transactionInfoList = getTransactionInfoByBlockNum(blockNumber).getTransactionInfoList();
}
List<TransactionInfo> transactionInfoList;
// Optimization: If the block result is already in memory, use it directly.
// Avoids re-querying the database for data just written.
if (blockCapsule.getResult() != null) {
transactionInfoList = blockCapsule.getResult().getInstance().getTransactioninfoList();
} else {
transactionInfoList = getTransactionInfoByBlockNum(blockNumber).getTransactionInfoList();
}

@0xbigapple 0xbigapple closed this Jan 20, 2026
@0xbigapple 0xbigapple reopened this Jan 20, 2026
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This pull request introduces a valuable optimization to the postLogsFilter method by caching transaction info in memory to reduce database queries. The implementation is clear and effective.

🔍 General Feedback

  • The code change is well-implemented and includes explanatory comments.
  • The logic for falling back to a database query is sound.
  • A minor suggestion for improving variable scope has been noted in an inline comment.


private void postLogsFilter(final BlockCapsule blockCapsule, boolean solidified,
boolean removed) {
long blockNumber = blockCapsule.getNum();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 For better scoping, consider moving the declaration of blockNumber inside the following if block, as it is only used there.

@0xbigapple 0xbigapple closed this Jan 20, 2026
@0xbigapple 0xbigapple reopened this Jan 20, 2026
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

The pull request introduces an optimization to avoid an unnecessary database query by using in-memory data when available. The change is logical and improves performance.

🔍 General Feedback

  • The code is well-commented, explaining the purpose of the optimization. I've added a minor suggestion to improve readability and avoid redundant method calls.

Comment on lines +2274 to +2279
// Optimization: If the block result is already in memory, use it directly.
// Avoids re-querying the database for data just written.
if (blockCapsule.getResult() != null) {
transactionInfoList = blockCapsule.getResult().getInstance().getTransactioninfoList();
} else {
// Fallback to querying from DB if not available in memory.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 For better readability and to avoid multiple calls to getResult(), you can store the result of blockCapsule.getResult() in a local variable.

Suggested change
// Optimization: If the block result is already in memory, use it directly.
// Avoids re-querying the database for data just written.
if (blockCapsule.getResult() != null) {
transactionInfoList = blockCapsule.getResult().getInstance().getTransactioninfoList();
} else {
// Fallback to querying from DB if not available in memory.
List<TransactionInfo> transactionInfoList;
// Optimization: If the block result is already in memory, use it directly.
// Avoids re-querying the database for data just written.
var blockResult = blockCapsule.getResult();
if (blockResult != null) {
transactionInfoList = blockResult.getInstance().getTransactioninfoList();
} else {
// Fallback to querying from DB if not available in memory.
transactionInfoList = getTransactionInfoByBlockNum(blockNumber).getTransactionInfoList();
}

@0xbigapple 0xbigapple closed this Jan 20, 2026
@0xbigapple 0xbigapple reopened this Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants