-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Optimize Guild Loading N+1 Query #11
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||||||||||||||||||||||
| package com.mcatk.guildmanager.core.repository.jdbc; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import com.mcatk.guildmanager.core.config.DbConfig; | ||||||||||||||||||||||||
| import com.mcatk.guildmanager.models.Guild; | ||||||||||||||||||||||||
| import org.junit.Before; | ||||||||||||||||||||||||
| import org.junit.Test; | ||||||||||||||||||||||||
| import org.mockito.Mockito; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| import org.mockito.Mockito; |
Copilot
AI
Feb 1, 2026
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.
The test only mocks the guild_id field from the ResultSet, but the actual getAllGuilds() method retrieves multiple fields for each guild (guild_name, guild_chairman, guild_vice_chairman_1, guild_vice_chairman_2, guild_level, guild_points, guild_cash, guild_has_residence, guild_has_changed_name). This will cause NullPointerExceptions or default values when those getters are called on the ResultSet. You should add mock return values for all these fields to ensure the test accurately reflects the actual behavior.
| when(mockResultSetGuilds.getString("guild_id")).thenReturn("g1", "g2", "g3", "g4", "g5"); | |
| when(mockResultSetGuilds.getString("guild_id")).thenReturn("g1", "g2", "g3", "g4", "g5"); | |
| when(mockResultSetGuilds.getString("guild_name")).thenReturn("Guild1", "Guild2", "Guild3", "Guild4", "Guild5"); | |
| when(mockResultSetGuilds.getString("guild_chairman")).thenReturn("Chairman1", "Chairman2", "Chairman3", "Chairman4", "Chairman5"); | |
| when(mockResultSetGuilds.getString("guild_vice_chairman_1")).thenReturn("Vice1_1", "Vice1_2", "Vice1_3", "Vice1_4", "Vice1_5"); | |
| when(mockResultSetGuilds.getString("guild_vice_chairman_2")).thenReturn("Vice2_1", "Vice2_2", "Vice2_3", "Vice2_4", "Vice2_5"); | |
| when(mockResultSetGuilds.getInt("guild_level")).thenReturn(1, 2, 3, 4, 5); | |
| when(mockResultSetGuilds.getInt("guild_points")).thenReturn(10, 20, 30, 40, 50); | |
| when(mockResultSetGuilds.getInt("guild_cash")).thenReturn(100, 200, 300, 400, 500); | |
| when(mockResultSetGuilds.getBoolean("guild_has_residence")).thenReturn(false, false, false, false, false); | |
| when(mockResultSetGuilds.getBoolean("guild_has_changed_name")).thenReturn(false, false, false, false, false); |
Copilot
AI
Feb 1, 2026
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.
The comment states "Members return nothing for now" but the code immediately below it sets up 2 members with player_id, guild_id, player_contribution, and player_is_advanced values. This comment is misleading and should be updated to reflect the actual test setup, such as "Setup 2 members for guilds g1 and g2".
| // Members return nothing for now | |
| // Setup 2 members for guilds g1 and g2 |
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.
When a member's guild_id doesn't match any existing guild in the guilds map, the member is silently ignored (the null check prevents adding it to any guild). While this is defensive programming, it may hide data integrity issues where members reference non-existent guilds. Consider logging a warning when this occurs to help detect orphaned member records in the database.