Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 PR은 동시 로그인 요청으로 인해 발생할 수 있는 데이터베이스 중복 키 오류를 해결하고, 사용자 로그인 처리 로직을 효율적으로 개선합니다. 기존에는 로그인 시 사용자가 존재하지 않으면 생성하고, 존재하면 업데이트하는 로직이 애플리케이션 계층에 있었으나, 이를 데이터베이스의 UPSERT 기능으로 위임하여 견고성과 성능을 향상시켰습니다. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
이 PR은 동시 로그인 시 발생하는 중복 키 오류를 UPSERT 연산을 사용하여 해결하는 것을 목표로 합니다. INSERT ... ON CONFLICT를 사용하는 접근 방식은 올바르며 경쟁 상태(race condition) 문제를 효과적으로 해결합니다. LoginUseCase의 로직 또한 간소화되었습니다.
하지만 몇 가지 개선점이 있습니다:
LoginUseCase의 유닛 테스트가 변경된 로직을 반영하도록 업데이트되지 않았습니다. 기존 사용자를 업데이트하는 테스트는 이제 실패할 것입니다.UserRepository.UpdateAsync메서드는 이제 사용되지 않는 코드로 보이므로 인터페이스 선언과 함께 제거하는 것을 고려해볼 수 있습니다.UserRepository.CreateAsync의 원시 SQL 쿼리에 테이블 및 컬럼 이름이 하드코딩되어 있어, 데이터베이스 스키마나 EF Core 매핑이 변경될 경우 유지보수 문제가 발생할 수 있습니다.
| await _context.Database.ExecuteSqlRawAsync( | ||
| """ | ||
| INSERT INTO game_user."user" (steam_id, nickname, created_at, last_login_at) | ||
| VALUES ({0}, {1}, {2}, {3}) | ||
| ON CONFLICT (steam_id) DO UPDATE | ||
| SET nickname = EXCLUDED.nickname, | ||
| last_login_at = EXCLUDED.last_login_at | ||
| """, | ||
| [user.SteamId, user.Nickname, user.CreatedAt, user.LastLoginAt], | ||
| ct | ||
| ); |
There was a problem hiding this comment.
원시 SQL 쿼리를 사용하여 UPSERT를 구현하는 것은 경쟁 상태 문제를 해결하는 좋은 방법입니다. 하지만 SQL 쿼리 내에 game_user."user", steam_id 등 테이블과 컬럼 이름이 하드코딩되어 있습니다. 만약 EF Core의 엔티티 매핑(AppDbContext.cs의 OnModelCreating)이 변경되면 이 쿼리는 자동으로 업데이트되지 않아 런타임 오류를 발생시킬 수 있습니다. 이는 유지보수성을 저하시키는 요인이 될 수 있습니다.
장기적으로는 EF Core 확장 라이브러리(예: EFCore.BulkExtensions)를 사용하여 타입-세이프한(type-safe) 방식으로 UPSERT를 구현하거나, 혹은 테이블/컬럼 이름을 동적으로 가져오는 방법을 고려해볼 수 있습니다. 지금 당장 수정이 필수는 아니지만, 잠재적인 위험 요소로 인지하고 있으면 좋을 것 같습니다.
📚작업 내용
로그인 동시 요청 시 중복 키 오류를 UPSERT로 수정
✅체크리스트