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

[REFACTOR] 게임 목록 조회 커서 페이징 쿼리 개선 #100 #101

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

ldk980130
Copy link
Contributor

🌍 이슈 번호

📝 구현 내용

기존에 스트링 concat을 기준으로 정렬 및 커서 페이징을 수행했던 것을 순수하게 and, or 조건 쿼리로 개선했습니다.

아래 처럼 BooleanBuilderand() 메서드 하나에 조건들을 넣으면 괄호를 씌울 수 있는 것을 확인해서 개선해보았습니다.

        DynamicBooleanBuilder booleanBuilder = DynamicBooleanBuilder.builder()
                .and(() -> game.league.id.eq(gamesQueryRequestDto.getLeagueId()))
                .and(() -> game.state.eq(state))
                .and(() -> game.sport.id.in(gamesQueryRequestDto.getSportIds()));
        if (state == GameState.FINISHED) {
            return booleanBuilder
                    .and(() -> game.startTime.eq(cursorStartTime).and(game.id.lt(cursor))
                            .or(game.startTime.lt(cursorStartTime)))
                    .build();
        }
image

테스트는 전부 통과합니다

🍀 확인해야 할 부분

  • 이 PR이 머지되면 개선된 쿼리를 대상으로 어떻게 인덱스를 넣으면 좋을지 성능 테스트를 해볼 생각입니다.

Copy link
Contributor

@Jin409 Jin409 left a comment

Choose a reason for hiding this comment

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

성능 테스트 해보면 재밌겠네요! 수고하셨습니다 👍🏻

엇. 근데 제가 다시 쿼리를 잘 생각해서 보니

(g.start_time=?
and g.id>?) or
g.start_time > ?

이렇게 되어야 하지 않나요?

and 가 더 높은 우선순위를 가지니 괜찮으려나요?

@ldk980130 ldk980130 merged commit 3f87b07 into main Feb 2, 2024
1 check passed
@ldk980130 ldk980130 deleted the refactor/#100-query-games branch February 2, 2024 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR] 게임 목록 조회 쿼리 개선
2 participants