Cache query strings in SimpleJpaRepository to improve performance #3920
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Optimizes SimpleJpaRepository by caching the query strings used for deleteAll and count operations.
Previously, the query strings for deleteAll and count were generated on each method invocation, causing repeated operations and unnecessary object creation. By caching these strings, we reduce redundant computation and improve performance, especially in applications with frequent batch delete or count operations.
The change would be safe as the query strings are based on immutable entity metadata and do not change during the repository's lifecycle.
Please review if there are scenarios where the entity metadata might change after repository construction, which could affect the correctness of the cached queries.
Let me know if you have any concerns or suggestions for further improvement!