⚡ Optimize addGems to use single atomic DB query #7
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.
This PR optimizes the
addGemsfunctionality inGemExecutorby replacing a sequence of inefficient database operations (multiple reads, check-if-null, insert, multiple writes) with a single atomicINSERT INTO ... ON DUPLICATE KEY UPDATEquery.Performance Improvement:
addGemscall resulted in up to 6 database queries (Select gems, Select gems again, Insert if null, Select total, Update gems, Update total).addGemscall results in exactly 1 database query.Verification:
GemExecutorTestwhich mocksMySQLManagerandGemplugin.addGemsis called exactly once and no other DB methods are invoked.Changes:
modules/Gem/src/main/java/com/mcatk/gem/sql/MySQLManager.java: AddedaddGemsmethod.modules/Gem/src/main/java/com/mcatk/gem/GemExecutor.java: RefactoredaddGemsto use the new SQL method.modules/Gem/src/test/java/com/mcatk/gem/GemExecutorTest.java: Added unit test.modules/Gem/pom.xml: Added JUnit/Mockito dependencies and fixed PlaceholderAPI repo/version.modules/Gem/src/main/java/com/mcatk/gem/Gem.java: Removedfinalkeyword to allow mocking.PR created automatically by Jules for task 2166190706997680899 started by @acsoto