repositoryのGetGameCreatorsByGameID#1578
Conversation
📝 WalkthroughWalkthroughThis PR implements the ChangesGameCreator User Lookup
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
3bcbc51 to
40240ff
Compare
|
Migrate lint ✅ Lint output |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1578 +/- ##
==========================================
- Coverage 52.13% 51.81% -0.32%
==========================================
Files 143 145 +2
Lines 10713 10836 +123
==========================================
+ Hits 5585 5615 +30
- Misses 4800 4891 +91
- Partials 328 330 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mathsuky
left a comment
There was a problem hiding this comment.
ありがとうございます!
2点コメントしたのでご確認お願い致します:bow-nya:
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/repository/gorm2/game_creator.go (1)
184-193: 💤 Low valueConsider an early return when
userIDsis empty.When
userIDsis emptyuserUUIDsbecomes[]uuid.UUID{}. GORM v2 convertsWHERE user_id IN ?with an empty slice intoIN (NULL), which returns zero rows safely — no crash. But it still pays the cost of a DB round-trip that can never produce results.♻️ Proposed optimization
userUUIDs := make([]uuid.UUID, 0, len(userIDs)) for _, userID := range userIDs { userUUIDs = append(userUUIDs, uuid.UUID(userID)) } + + if len(userUUIDs) == 0 { + return []*domain.GameCreator{}, nil + } + var gameCreators []schema.GameCreatorTable🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/repository/gorm2/game_creator.go` around lines 184 - 193, When userIDs is empty, avoid the unnecessary DB query: add an early return before the conversion loop and GORM call (check len(userIDs) == 0) and return an empty []schema.GameCreatorTable (or the same zero-value result and nil error expected by the surrounding function) instead of executing the db.Where(...).Where("user_id IN ?", userUUIDs).Find(&gameCreators).Error. This prevents building userUUIDs and issuing the GORM IN query with an empty slice while preserving the existing return types/behavior of the function that contains userIDs, userUUIDs, and the gameCreators query.src/repository/gorm2/game_creator_test.go (1)
755-763: ⚡ Quick winAssociated
GameTable2records are not cleaned up.When
db.Create(testCase.creators)runs, GORM implicitly creates the associatedGameTable2records (forcreatorSchema1.Game,creatorSchema2.Game, andcreatorSchema3.Game). The cleanup only deletes theGameCreatorTablerows:err = db.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(testCase.creators).ErrorThe
GameTable2records remain in the database. Compare withTestGetGameCreatorsByGameID(lines 39–44) which adds an explicit global cleanup for&schema.GameTable2{}. Without similar cleanup here, game records leak across subtests, and if this test function runs in isolation or last in the suite, those records persist indefinitely.Add a
t.Cleanupoutside the subtest loop (or inside withclause.Associations) to remove the game records:♻️ Proposed fix
for name, testCase := range testCases { t.Run(name, func(t *testing.T) { ctx := t.Context() db, err := testDB.getDB(ctx) require.NoError(t, err) if len(testCase.creators) > 0 { err = db.Create(testCase.creators).Error require.NoError(t, err) t.Cleanup(func() { db, err := testDB.getDB(context.Background()) require.NoError(t, err) - err = db.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(testCase.creators).Error + err = db.Select(clause.Associations).Delete(testCase.creators).Error require.NoError(t, err) }) }Alternatively, add a top-level
t.Cleanup(after all subtests) to globally wipeGameTable2, matching the pattern used byTestGetGameCreatorsByGameID.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/repository/gorm2/game_creator_test.go` around lines 755 - 763, The cleanup currently removes only testCase.creators after db.Create(testCase.creators) but not the implicitly created GameTable2 rows; update the test to also remove those game records by adding a t.Cleanup that calls db.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(&schema.GameTable2{}) (or, if deleting per-subtest, call Delete(testCase.creators, clause.Associations) to cascade associations) so that the GameTable2 rows created by db.Create(testCase.creators) are removed and do not leak between subtests; reference testCase.creators, db.Create, and schema.GameTable2 when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/repository/gorm2/game_creator_test.go`:
- Around line 755-763: The cleanup currently removes only testCase.creators
after db.Create(testCase.creators) but not the implicitly created GameTable2
rows; update the test to also remove those game records by adding a t.Cleanup
that calls db.Session(&gorm.Session{AllowGlobalUpdate:
true}).Delete(&schema.GameTable2{}) (or, if deleting per-subtest, call
Delete(testCase.creators, clause.Associations) to cascade associations) so that
the GameTable2 rows created by db.Create(testCase.creators) are removed and do
not leak between subtests; reference testCase.creators, db.Create, and
schema.GameTable2 when making the change.
In `@src/repository/gorm2/game_creator.go`:
- Around line 184-193: When userIDs is empty, avoid the unnecessary DB query:
add an early return before the conversion loop and GORM call (check len(userIDs)
== 0) and return an empty []schema.GameCreatorTable (or the same zero-value
result and nil error expected by the surrounding function) instead of executing
the db.Where(...).Where("user_id IN ?", userUUIDs).Find(&gameCreators).Error.
This prevents building userUUIDs and issuing the GORM IN query with an empty
slice while preserving the existing return types/behavior of the function that
contains userIDs, userUUIDs, and the gameCreators query.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 504c2f6f-2391-4a4e-9161-ab7d40097413
📒 Files selected for processing (2)
src/repository/gorm2/game_creator.gosrc/repository/gorm2/game_creator_test.go
fix #1528
Summary by CodeRabbit
New Features
Tests