-
Notifications
You must be signed in to change notification settings - Fork 16
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
좋아요 기능 버그 해결을 위한 캐싱 자료구조 및 로직 변경 #788
Merged
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
ce62e0f
Merge pull request #683 from woowacourse-teams/hotfix/#682
dladncks1217 0b53fb4
Merge pull request #735 from woowacourse-teams/develop
LJW25 8fa3188
Update README.md
hgo641 891814a
Merge pull request #783 from woowacourse-teams/develop
mcodnjs c033764
fix: LikeCount 업데이트 로직 수정
mcodnjs 52b1d06
refactor: updateMemberLikeCache 메서드 분리
mcodnjs ccbc23b
fix: 커뮤니티 여행 전체 조회 시 Redis 사용하도록 수정
mcodnjs 968ca26
feat: RedisTemplate 빈 등록
mcodnjs 5689976
feat: 좋아요 업데이트 로직 구현
mcodnjs 12d48c8
feat: db와 redis 동기화 스케줄러 구현
mcodnjs 5373b30
feat: 좋아요 조회 로직 구현
mcodnjs 23378f7
refactor: 사용하지 않는 메서드 삭제
mcodnjs 7109d2d
refactor: LikeElement 필드 변경
mcodnjs d1c4364
refactor: Likes 테이블에 없는 tripId에 default 값 할당
mcodnjs 418b3e6
refactor: LikeRedisKeyConstants 생성
mcodnjs 64dbb6f
refactor: 사용하지 않는 dto 삭제
mcodnjs 90984b3
refactor: like ttl 상수화
mcodnjs ee61595
fix: likes 테이블 소문자로 변경
mcodnjs 79335e8
fix: 커스텀 쿼리로 변경
mcodnjs 56bb511
fix: 캐시된 tripId가 하나라도 있을 경우만 db 조회하도록 변경
mcodnjs 7043b79
fix: likes 조회 시 memberIds 파싱 로직 수정
mcodnjs 2ea5b03
fix: redis에 가변인자로 추가하도록 변경
mcodnjs 4583c0e
fix: like key prefix 수정
mcodnjs 68882fe
fix: like key prefix 수정
mcodnjs 2378fa4
fix: empty_marker 타입 변경
mcodnjs 7c2e8ff
fix: 업데이트 시 캐시가 없는 경우 DB에서 조회해오도록 수정
mcodnjs d33ccad
refactor: 업데이트 메서드 인자 수정 및 로직 리팩토링
mcodnjs 59edb00
refactor: toLikeInfo로 메서드 네이밍 변경
mcodnjs c658576
refactor: likeElements로 변수명 변경
mcodnjs 4a62d4c
refactor: 메서드 위치 변경
mcodnjs babb205
refactor: 메서드명 변경 및 LikeInfo dto 패키지로 이동
mcodnjs 8530e26
test: LikeService 테스트 추가
mcodnjs 339be7b
test: LikeSyncScheduler 테스트 추가
mcodnjs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/hanglog/like/domain/repository/CustomLikeRepository.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package hanglog.like.domain.repository; | ||
|
||
import hanglog.like.domain.Likes; | ||
import hanglog.like.dto.LikeElement; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface CustomLikeRepository { | ||
|
||
void saveAll(final List<Likes> likes); | ||
|
||
Optional<LikeElement> findLikesElementByTripId(final Long tripId); | ||
|
||
List<LikeElement> findLikeElementByTripIds(final List<Long> tripIds); | ||
} |
22 changes: 2 additions & 20 deletions
22
backend/src/main/java/hanglog/like/domain/repository/LikeRepository.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,14 @@ | ||
package hanglog.like.domain.repository; | ||
|
||
import hanglog.like.domain.Likes; | ||
import hanglog.like.dto.LikeElement; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface LikeRepository extends JpaRepository<Likes, Long> { | ||
|
||
@Query(value = """ | ||
SELECT l.trip_id AS tripId, COUNT(l.id) AS likeCount, GROUP_CONCAT(l.member_id) AS memberIds | ||
FROM likes l | ||
WHERE l.trip_id IN :tripIds | ||
GROUP BY l.trip_id | ||
""", nativeQuery = true) | ||
List<LikeElement> findLikeElementByTripIds(@Param("tripIds") final List<Long> tripIds); | ||
|
||
@Query(value = """ | ||
SELECT l.trip_id AS tripId, COUNT(l.id) AS likeCount, GROUP_CONCAT(l.member_id) AS memberIds | ||
FROM likes l | ||
WHERE l.trip_id = :tripId | ||
GROUP BY l.trip_id | ||
""", nativeQuery = true) | ||
Optional<LikeElement> findLikesElementByTripId(@Param("tripId") final Long tripId); | ||
|
||
@Modifying | ||
@Query("DELETE FROM Likes WHERE tripId IN :tripIds") | ||
void deleteByTripIds(final Set<Long> tripIds); | ||
} |
This file contains 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
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.
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.
요 아래 메서드들 왜
LikeRepository
에서CustomLikeRepository
로 옮겨진 건가요?@Query
가독성이 나빠서인가요?.? 궁금합니닷.달라진 게 parseMemberIds()가 추가된 것 말고는 모르겠는데 혹시 이전 메서드에서는 memberIds가 제대로 안불러와졌던건가요?..?
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.
음음 일단, 기존에 사용하던 쿼리랑 뽑아오는 값이 달라요!!!
GROUP_CONCAT
쪽 주의!!Redis 자료구조를 Set으로 사용하면서 특정 멤버가 좋아요 했는지 여부 뿐만 아니라 memberId 정보를 모두 캐싱해야 했어요!!
그래서
isLike
를 뽑아오던 기존에 쿼리 대신Set<memberId>
이 친구를 뽑아오는 쿼리로 변경하였는데,하이버네이트 문법 상으로
GROUP_CONCAT
은 적용할 수 없는 한계가 있었고,nativeQuery
옵션을 주면 쿼리는 잘 날라가는데 반환값이LikeElement
로 매핑이 안되서 직접 파싱해줘야 했어요 ㅠㅅㅠ 그래서 쩔 수 없이 직접 구현했습니다 ㅎㅎ ..