-
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 all commits
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
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
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/hanglog/like/domain/LikeRedisConstants.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package hanglog.like.domain; | ||
|
||
import java.time.Duration; | ||
|
||
public class LikeRedisConstants { | ||
|
||
public static final String LIKE_KEY_PREFIX = "like:"; | ||
public static final String WILD_CARD = "*"; | ||
public static final String KEY_SEPARATOR = ":"; | ||
public static final Long EMPTY_MARKER = -1L; | ||
public static final Duration LIKE_TTL = Duration.ofMinutes(90L); | ||
|
||
public static String generateLikeKey(final Long tripId) { | ||
return LIKE_KEY_PREFIX + tripId; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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); | ||
} |
10 changes: 0 additions & 10 deletions
10
backend/src/main/java/hanglog/like/domain/repository/LikeCountRepository.java
This file was deleted.
Oops, something went wrong.
36 changes: 5 additions & 31 deletions
36
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,40 +1,14 @@ | ||
package hanglog.like.domain.repository; | ||
|
||
import hanglog.like.domain.Likes; | ||
import hanglog.like.dto.LikeElement; | ||
import hanglog.like.dto.TripLikeCount; | ||
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(""" | ||
SELECT new hanglog.like.dto.LikeElement | ||
(l.tripId, COUNT(l.memberId), EXISTS(SELECT 1 FROM Likes l_1 WHERE l_1.memberId = :memberId AND l_1.tripId = l.tripId)) | ||
FROM Likes l | ||
WHERE l.tripId in :tripIds | ||
GROUP BY l.tripId | ||
""") | ||
List<LikeElement> findLikeCountAndIsLikeByTripIds(@Param("memberId") final Long memberId, | ||
@Param("tripIds") final List<Long> tripIds); | ||
|
||
@Query(""" | ||
SELECT new hanglog.like.dto.LikeElement | ||
(l.tripId, COUNT(l.memberId), EXISTS(SELECT 1 FROM Likes l_1 WHERE l_1.memberId = :memberId AND l_1.tripId = l.tripId)) | ||
FROM Likes l | ||
WHERE l.tripId = :tripId | ||
GROUP BY l.tripId | ||
""") | ||
Optional<LikeElement> findLikeCountAndIsLikeByTripId(@Param("memberId") final Long memberId, | ||
@Param("tripId") final Long tripId); | ||
|
||
@Query(""" | ||
SELECT new hanglog.like.dto.TripLikeCount(l.tripId, COUNT(l.memberId)) | ||
FROM Likes l | ||
GROUP BY l.tripId | ||
""") | ||
List<TripLikeCount> findCountByAllTrips(); | ||
@Modifying | ||
@Query("DELETE FROM Likes WHERE tripId IN :tripIds") | ||
void deleteByTripIds(final Set<Long> tripIds); | ||
} |
7 changes: 0 additions & 7 deletions
7
backend/src/main/java/hanglog/like/domain/repository/MemberLikeRepository.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
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.
야무지네요