-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Optimization postLogsFilter #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/gemini
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
| // Avoids re-querying the database for data just written. | |
| transactionInfoList = blockCapsule.getResult().getInstance().getTransactionInfoList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| // 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(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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(); | |
| } |
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
| // 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. |
There was a problem hiding this comment.
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.
| // 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(); | |
| } |
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:
Follow up
Extra details