8000 [Feature] 사용자 통계에 다수 선택 일치율 추가 by wngktjd13 · Pull Request #51 · If-u-Lab/If-u-server · GitHub
[go: up one dir, main page]

Skip to content

[Feature] 사용자 통계에 다수 선택 일치율 추가 - #51

Merged
wngktjd13 merged 2 commits into
devfrom
feature/majority
Dec 26, 2025
Merged

wngktjd13 merged 2 commits into
devfrom
feature/majority

Conversation

@wngktjd13
@wngktjd13 wngktjd13 commented Dec 26, 2025 •
Copy link
Copy Markdown
Member

🔗 Issue Link

🎯 What I Did

  • 사용자 통계(GET /api/v1/users/me)에 다수 선택 일치율(majorityRate) 필드 추가
  • DB 쿼리 최적화 (7개 → 5개)

🔍 Review Points

  • calculateMajorityRate() 로직: 동점일 경우 어느 쪽이든 다수 선택으로 인정
  • 투표 목록 재사용으로 countByUserId, countDistinctQuestionsByUserId 쿼리 제거

🧪 API Test Scenarios

테스트한 엔드포인트

  • GET /api/v1/users/me

테스트 시나리오

  1. 정상 플로우
    • 투표 이력이 있는 사용자 조회 시 stats.majorityRate 반환 확인
    • 투표 이력이 없는 사용자 조회 시 majorityRate: 0.0 반환 확인
  2. 에러 케이스
    • 미인증 요청 시 401 반환

✅ Checklist

  • Swagger 문서화 완료 (@Operation, @ApiResponse, @ApiErrorExample(s) 등)
  • 필요시 Notion 문서화 완료

@wngktjd13 wngktjd13 self-assigned this Dec 26, 2025
@wngktjd13 wngktjd13 added the enhancement New feature or request label Dec 26, 2025
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @wngktjd13, 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은 사용자 통계 API(GET /api/v1/users/me)에 사용자의 투표가 다수 선택과 얼마나 일치하는지를 나타내는 majorityRate 필드를 새롭게 도입합니다. 이 기능 추가와 함께, 사용자 통계 정보를 가져오는 과정에서 발생하는 데이터베이스 쿼리 수를 줄여 전반적인 성능을 향상시키는 중요한 최적화 작업이 이루어졌습니다.

Highlights

  • 사용자 통계에 다수 선택 일치율 추가: 사용자 통계 API 응답에 majorityRate 필드가 추가되었습니다.
  • DB 쿼리 최적화: 사용자 통계 조회 시 발생하는 DB 쿼리 수가 7개에서 5개로 최적화되었습니다.
  • 다수 선택 일치율 계산 로직 구현: 다수 선택 일치율 계산 로직(calculateMajorityRate)이 구현되었으며, 동점일 경우 choice1을 다수 선택으로 처리합니다.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@claude
claude Bot commented Dec 26, 2025
Copy link
Copy Markdown

PR 리뷰

전반적으로 깔끔한 구현입니다. 투표 목록을 재사용하여 쿼리를 7개에서 5개로 줄인 최적화가 좋습니다.

P2 (적극적으로 고려해주세요)

  • UserService.java:124 - 동점일 경우 choice1을 다수파로 처리하는 로직이 명시되어 있으나, 이는 비즈니스 요구사항에 따라 논란의 여지가 있습니다. 동점인 경우 사용자가 어느 쪽을 선택했든 다수파로 인정하는 것이 더 공정할 수 있습니다. (현재: choice1만 우대)

  • UserService.java:120-123 - VoteStats가 null인 경우를 처리하고 있으나, Question과 VoteStats는 OneToOne 관계로 생성 시 함께 생성되어야 합니다. null 케이스가 실제로 발생할 수 있는지 확인이 필요합니다. 발생 가능하다면 로그를 남기는 것이 좋습니다.

P3 (웬만하면 반영해주세요)

  • UserService.java:113-130 - calculateMajorityRate() 메서드에 대한 단위 테스트 추가를 권장합니다. 특히 동점 처리 로직과 빈 투표 목록, VoteStats null 케이스를 검증하는 테스트가 필요합니다.

  • VoteRepository.java:42-46 - JPQL에서 JOIN FETCH와 LEFT JOIN FETCH를 혼용하고 있습니다. Question과 VoteStats의 관계가 항상 존재한다면 JOIN FETCH로 통일하는 것이 의도를 더 명확하게 전달합니다.

  • UserResponse.java:47 - majorityRate 필드에 대한 JavaDoc 주석이 누락되었습니다. 다른 필드들과의 일관성을 위해 추가를 권장합니다.

P4 (반영해도 좋고 넘어가도 좋습니다)

  • UserService.java:77 - 주석 "VoteStats와 함께"를 "및 Question 정보"로 보완하면 JOIN FETCH의 범위가 더 명확합니다.

@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

이번 PR은 사용자 통계에 다수 선택 일치율을 추가하고 관련 데이터베이스 쿼리를 최적화하는 변경 사항을 담고 있습니다. 전반적으로 좋은 방향의 개선이며, 특히 findByUserIdWithVoteStats 쿼리를 통해 여러 쿼리를 하나로 통합하여 성능을 개선한 점이 인상적입니다. 코드의 가독성과 유지보수성을 더욱 향상시키기 위해 몇 가지 리팩토링 제안을 드립니다. UserService에서 중복되는 백분율 계산 로직을 헬퍼 메서드로 추출하고, 다수파 투표 여부를 확인하는 로직을 별도 메서드로 분리하여 스트림 표현식을 더 간결하게 만드는 것을 고려해 보시기 바랍니다.

@claude
claude Bot commented Dec 26, 2025
Copy link
Copy Markdown

코드 리뷰

전반적으로 쿼리 최적화가 잘 이루어졌고, 다수 선택 일치율 계산 로직이 명확합니다. 몇 가지 개선 사항을 제안드립니다.

P2 (적극적으로 고려해주세요)

  • VoteRepository.java:42-45 - JOIN FETCH v.question q 쿼리가 모든 투표를 조회하므로 사용자가 투표를 많이 한 경우 성능 이슈가 발생할 수 있습니다. 페이징 처리나 데이터 제한 검토를 권장합니다.

  • UserService.java:123-137 - isMajorityVote() 메서드에서 VoteStats null 체크 시 false를 반환하는데, 이 경우 다수파 비율 계산이 부정확해질 수 있습니다. VoteStats가 null인 경우 예외를 발생시키거나 별도 처리가 필요합니다.

  • UserService.java:131-132 - 동점일 때 무조건 true 반환하는 것이 비즈니스 요구사항과 맞는지 확인이 필요합니다. PR 설명에는 "choice1을 다수 선택으로 처리"라고 되어 있어 불일치가 있습니다.

P3 (웬만하면 반영해주세요)

  • UserService.java:111-121 - calculateMajorityRate() 메서드에 대한 단위 테스트 추가를 권장합니다. 특히 동점 케이스와 VoteStats null 케이스 검증이 중요합니다.

  • UserResponse.java:47 - Swagger 문서에 majorityRate 필드 설명 추가 필요 (예: @Schema(description = "다수 선택 일치율 (0-100)"))

P4 (반영해도 좋고 넘어가도 좋습니다)

  • UserService.java:77 - 주석 "totalVotes, majorityRate 계산에 재사용" 중 participationRate도 재사용하므로 수정 권장

긍정적인 부분

쿼리 최적화로 7개 → 5개 감소는 효과적이며, calculatePercentage() 메서드 추출로 중복 제거가 잘 되었습니다.

@wngktjd13
wngktjd13 merged commit 44d953e into dev Dec 26, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0