[SCRUM-312] 코스 요약 조회의 즐길거리 조회 쿼리 수정 (#144)#146
Merged
Conversation
LEFT JOIN을 INNER JOIN으로 변경하여 이미지가 있는 즐길거리 중에서 랜덤으로 3개만 조회하도록 쿼리를 수정했습니다.
moonxxpower
approved these changes
Sep 25, 2025
Member
There was a problem hiding this comment.
확인했습니다 👍
혹시 즐길거리 이미지가 아예 없는 경우, 빈 값으로 응답하는 것을 방지하기 위해 아래와 같이 쿼리 작성하면 어떨까요? 해당 상황이 거의 없을 것 같긴한데 만약에 모든 즐길거리에 이미지가 없는 코스가 있다면 즐길거리가 있더라도 요약 조회에서 빈 값으로 반환될거 같아서요!
SELECT
s.spot_id AS spotId,
s.name,
s.description,
si.img_url AS imageUrl
FROM
spot s
JOIN
course_spot cs ON s.spot_id = cs.spot_id
LEFT JOIN
spot_image si ON s.spot_id = si.spot_id
WHERE
cs.course_id = :courseId
ORDER BY
(si.img_url IS NOT NULL) DESC,
RAND()
LIMIT 3
기존 쿼리는 모든 즐길거리의 이미지가 없는 경우, 즐길거리가 존재하더라도 빈 데이터를 반환하는 문제가 있었습니다. 해당 문제를 해결하기 위해 spot_image 테이블을 LEFT JOIN으로 묶고, ORDER BY를 사용하여 이미지가 있는 즐길거리부터 우선적으로 반환하도록 수정했습니다. 이를 통해 모든 즐길거리의 이미지가 없는 경우에도 항상 데이터를 반환하여 API 안정성을 높였습니다.
Contributor
Author
|
좋은 의견 감사합니다! 그 엣지 케이스를 고려 못했네요. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✏️ 연관 이슈
#144
⛳ 작업 내용
spotRepository.findRandom3ByCourseId쿼리 수정💬리뷰 요구사항
.
📍 참고사항
.