-
Notifications
You must be signed in to change notification settings - Fork 0
[Quiz][Refactor] 퀴즈 생성 중 타유저가 생성요청 보내더라도 타유저에게 퀴즈 생성 완료 알림을 보낸다 #203
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
Conversation
Summary of ChangesHello @sunwon12, 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! 이 풀 리퀘스트는 퀴즈 생성 시스템에서 다중 사용자 알림 기능을 개선하고 'Thundering Herd' 문제를 방지하기 위한 것입니다. 기존에는 퀴즈 생성 요청을 보낸 최초 사용자에게만 완료 알림이 전달되었으나, 이제는 퀴즈 생성 중 동일한 퀴즈에 대한 요청이 들어오면 해당 사용자들도 구독자로 등록되어 퀴즈 생성이 완료되었을 때 모두에게 알림이 발송되도록 변경되었습니다. 이를 통해 사용자 경험을 향상시키고 시스템의 멱등성을 유지하면서 효율적인 알림 처리를 가능하게 합니다. Highlights
🧠 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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new QuizSubscriber entity and repository to manage members who request quiz generation for a specific book. The core change modifies the quiz generation flow: when a quiz is requested, the requesting member is now recorded as a QuizSubscriber. If a quiz is already being generated, subsequent requests from other members will also add them as subscribers without re-initiating generation. Once quiz generation is successfully completed, the system now iterates through all recorded subscribers for that book, publishes a QuizCreatedEvent for each, and then clears all subscribers for that book. The QuizGenerationAsyncService and QuizGenerationService were updated to reflect these changes, including removing the memberId parameter from success handlers and incorporating the QuizSubscriberRepository. The QuizGenerationHandlerService now handles the event publishing and subscriber cleanup within a transactional context. Unit and integration tests were updated and new ones added to cover the new subscriber logic, including concurrent request scenarios. Review comments suggest improving the QuizSubscriber entity by removing redundant createdAt initialization in the constructor in favor of @CreatedDate with JPA Auditing, and optimizing the deleteAllByBookId method in QuizSubscriberRepository for better performance with large datasets by using a direct DELETE query. Another comment suggests considering stream-based processing for findAllByBookId in QuizGenerationHandlerService to handle a potentially large number of subscribers more efficiently.
| private void sendEventToAllRequesters(Book book) { | ||
| List<QuizSubscriber> subscribers = quizSubscriberRepository.findAllByBookId(book.getId()); | ||
| for (QuizSubscriber subscriber : subscribers) { | ||
| eventPublisher.publishEvent(new QuizCreatedEvent(book.getId(), subscriber.getMemberId())); | ||
| } | ||
| quizSubscriberRepository.deleteAllByBookId(book.getId()); | ||
| } |
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.
퀴즈 생성 완료 후 모든 구독자에게 알림을 보내는 로직이 추가되었네요. 한 가지 고려할 점은 findAllByBookId가 매우 많은 수의 구독자를 반환할 경우 메모리 사용량이 급증할 수 있다는 점입니다. 현재는 구독자 수가 많지 않을 것으로 예상되지만, 향후 확장성을 고려하여 Stream을 사용한 처리를 검토해볼 수 있습니다.
예를 들어, Stream<QuizSubscriber> findAllByBookId(Long bookId)와 같이 리포지토리 메서드를 변경하고 서비스에서 스트림을 순회하며 이벤트를 발행하면 대용량 데이터 처리 시 더 안정적일 수 있습니다. @Transactional(readOnly = true)와 함께 사용하면 더 효과적입니다.
Test Results102 files 102 suites 20s ⏱️ Results for commit 7975706. ♻️ This comment has been updated with latest results. |
🌻 테스트 커버리지 리포트
|
다중 사용자 퀴즈 알림 시스템
Before: 최초의 퀴즈 생성 요청자만 퀴즈 생성 완료를 보낸다. 문제는 1분 동안 퀴즈 생성 시 타유저가 요청을 보내면 멱등성은 보장되지만, 타유저가 알림을 받지 못함
After: 퀴즈 생성 중 타유저가 생성요청 보내더라도 타유저에게 퀴즈 생성 완료 알림을 보낸다
QuizSubscriber
도메인 추가: 특정 책의 퀴즈 생성을 기다리는 사용자 목록을 DB(quiz_subscriber)에 저장합니다.
레디스 zset 사용해서 알림 받을 사용자 저장을 고민하였지만, 레디스가 다운되더라도 퀴즈는 정상적으로 동작해야 하기 때문에 레디스를 사용하지 않았습니다
QuizGenerationService
개선: 퀴즈 생성 요청 시, 요청자를 구독자 목록에 추가합니다.
QuizGenerationHandlerService
개선: 퀴즈 생성이 완료되면 QuizSubscriber 테이블을 조회하여 기다리던 모든 사용자에게 알림 이벤트를 발행합니다. 알림 발송 후 해당 책퀴즈에 대한 구독자 목록을 정리합니다.
TODO