Skip to content
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

밸런스 게임 조회수가 증가하지 않는 이슈 #863

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

jschoi-96
Copy link
Contributor

@jschoi-96 jschoi-96 commented Jan 14, 2025

💡 작업 내용

  • @Transactional(readOnly = true)에서 readOnly 옵션 제거

💡 자세한 설명

기존에 readOnly = true 라는 조건을 붙이면서 게임을 조회할 때 update 쿼리가 실행되지 않았습니다.

따라서, views 필드가 조회를 해도 업데이트 되지 않고 그대로 0으로 남아있는 오류가 발생했습니다.

Hibernate: 
    select
        gs1_0.id,
        gs1_0.bookmarks,
        gs1_0.created_at,
        gs1_0.edited_at,
        gs1_0.last_modified_at,
        gs1_0.main_tag_id,
        gs1_0.member_id,
        gs1_0.notification_history_json,
        gs1_0.sub_tag,
        gs1_0.title,
        gs1_0.views 
    from
        game_set gs1_0 
    where
        gs1_0.id=?
...
Hibernate: 
    update
        game_set 
    set
        bookmarks=?,
        edited_at=?,
        last_modified_at=?,
        main_tag_id=?,
        member_id=?,
        notification_history_json=?,
        sub_tag=?,
        title=?,
        views=? 
    where
        id=?

@Transactional로 변경함에 따라 성공적으로 업데이트 쿼리가 나가는 것을 확인했습니다.

📗 참고 자료 (선택)

📢 리뷰 요구 사항 (선택)

🚩 후속 작업 (선택)

✅ 셀프 체크리스트

  • PR 제목을 형식에 맞게 작성했나요?
  • 브랜치 전략에 맞는 브랜치에 PR을 올리고 있나요?
  • 이슈는 close 했나요?
  • Reviewers, Labels, Projects를 등록했나요?
  • 작업 도중 문서 수정이 필요한 경우 잘 수정했나요?
  • 테스트는 잘 통과했나요?
  • 불필요한 코드는 제거했나요?

closes #862

Summary by CodeRabbit

  • 기능 변경
    • 게임셋 조회 메서드의 트랜잭션 관리 방식 업데이트
    • 읽기 전용 트랜잭션에서 표준 트랜잭션으로 변경
    • 데이터베이스 상호작용 방식에 잠재적 변경사항 적용

@jschoi-96 jschoi-96 added 🛠️ fix 오류 수정 D-0 긴급 이슈에 대한 작업 labels Jan 14, 2025
@jschoi-96 jschoi-96 self-assigned this Jan 14, 2025
Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Walkthrough

GameServicefindBalanceGameSet 메서드에서 트랜잭션 관리 방식이 변경되었습니다. 기존의 읽기 전용 트랜잭션에서 일반 트랜잭션으로 수정되어, 데이터베이스 상태 변경이 가능해졌습니다. 이 변경은 게임셋의 조회수를 증가시키는 로직과 관련이 있으며, 메서드의 기본 동작에는 큰 변화가 없습니다.

Changes

파일 변경 내용
src/main/java/balancetalk/game/application/GameService.java findBalanceGameSet 메서드의 @Transactional 어노테이션에서 readOnly = true 속성 제거

Assessment against linked issues

목표 해결 여부 설명
밸런스 게임 조회수 업데이트 문제 해결 [#862]

Poem

🐰 코드의 토끼, 트랜잭션을 뛰어넘어
조회수는 이제 자유롭게 춤을 추네
읽기 전용의 벽을 부수고
데이터는 생동감 넘치는 이야기를 쓰네
🎉 코드의 마법, 버그는 이제 안녕! 🚀

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/balancetalk/game/application/GameService.java (1)

154-156: @transactional 수정이 적절합니다.

readOnly=true 제거는 조회수 증가 기능을 정상적으로 동작하게 만드는 올바른 해결책입니다.

하지만 성능 최적화를 위해 읽기/쓰기 작업을 분리하는 것을 고려해보시기 바랍니다.

다음과 같이 리팩토링하는 것을 제안드립니다:

-    @Transactional
-    public GameSetDetailResponse findBalanceGameSet(final Long gameSetId, final GuestOrApiMember guestOrApiMember) {
-        GameSet gameSet = gameSetRepository.findById(gameSetId)
-                .orElseThrow(() -> new BalanceTalkException(ErrorCode.NOT_FOUND_BALANCE_GAME_SET));
-        gameSet.increaseViews();
+    @Transactional
+    public void increaseGameSetViews(final Long gameSetId) {
+        GameSet gameSet = gameSetRepository.findById(gameSetId)
+                .orElseThrow(() -> new BalanceTalkException(ErrorCode.NOT_FOUND_BALANCE_GAME_SET));
+        gameSet.increaseViews();
+    }
+
+    @Transactional(readOnly = true)
+    public GameSetDetailResponse findBalanceGameSet(final Long gameSetId, final GuestOrApiMember guestOrApiMember) {
+        increaseGameSetViews(gameSetId);
+        GameSet gameSet = gameSetRepository.findById(gameSetId)
+                .orElseThrow(() -> new BalanceTalkException(ErrorCode.NOT_FOUND_BALANCE_GAME_SET));

이렇게 분리하면 다음과 같은 이점이 있습니다:

  1. 조회 로직에 readOnly=true 최적화를 적용할 수 있습니다
  2. 단일 책임 원칙(SRP)을 더 잘 준수합니다
  3. 조회수 증가 로직을 다른 곳에서도 재사용할 수 있습니다
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e2a42b and e806645.

📒 Files selected for processing (1)
  • src/main/java/balancetalk/game/application/GameService.java (1 hunks)

@jschoi-96 jschoi-96 merged commit 18af582 into main Jan 15, 2025
4 checks passed
@jschoi-96 jschoi-96 deleted the bug/862-views-increase branch January 15, 2025 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D-0 긴급 이슈에 대한 작업 🛠️ fix 오류 수정
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

밸런스 게임을 클릭했을 떄 조회수 업데이트가 안되는 현상
3 participants