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

좋아요 기능 버그 해결을 위한 캐싱 자료구조 및 로직 변경 #791

Merged
merged 29 commits into from
Feb 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c033764
fix: LikeCount 업데이트 로직 수정
mcodnjs Jan 26, 2024
52b1d06
refactor: updateMemberLikeCache 메서드 분리
mcodnjs Jan 26, 2024
ccbc23b
fix: 커뮤니티 여행 전체 조회 시 Redis 사용하도록 수정
mcodnjs Jan 26, 2024
968ca26
feat: RedisTemplate 빈 등록
mcodnjs Jan 27, 2024
5689976
feat: 좋아요 업데이트 로직 구현
mcodnjs Jan 28, 2024
12d48c8
feat: db와 redis 동기화 스케줄러 구현
mcodnjs Jan 28, 2024
5373b30
feat: 좋아요 조회 로직 구현
mcodnjs Jan 28, 2024
23378f7
refactor: 사용하지 않는 메서드 삭제
mcodnjs Jan 28, 2024
7109d2d
refactor: LikeElement 필드 변경
mcodnjs Jan 29, 2024
d1c4364
refactor: Likes 테이블에 없는 tripId에 default 값 할당
mcodnjs Jan 29, 2024
418b3e6
refactor: LikeRedisKeyConstants 생성
mcodnjs Jan 29, 2024
64dbb6f
refactor: 사용하지 않는 dto 삭제
mcodnjs Jan 29, 2024
90984b3
refactor: like ttl 상수화
mcodnjs Jan 29, 2024
ee61595
fix: likes 테이블 소문자로 변경
mcodnjs Jan 29, 2024
79335e8
fix: 커스텀 쿼리로 변경
mcodnjs Jan 29, 2024
56bb511
fix: 캐시된 tripId가 하나라도 있을 경우만 db 조회하도록 변경
mcodnjs Jan 29, 2024
7043b79
fix: likes 조회 시 memberIds 파싱 로직 수정
mcodnjs Jan 29, 2024
2ea5b03
fix: redis에 가변인자로 추가하도록 변경
mcodnjs Jan 29, 2024
4583c0e
fix: like key prefix 수정
mcodnjs Jan 29, 2024
68882fe
fix: like key prefix 수정
mcodnjs Jan 30, 2024
2378fa4
fix: empty_marker 타입 변경
mcodnjs Jan 30, 2024
7c2e8ff
fix: 업데이트 시 캐시가 없는 경우 DB에서 조회해오도록 수정
mcodnjs Jan 31, 2024
d33ccad
refactor: 업데이트 메서드 인자 수정 및 로직 리팩토링
mcodnjs Jan 31, 2024
59edb00
refactor: toLikeInfo로 메서드 네이밍 변경
mcodnjs Jan 31, 2024
c658576
refactor: likeElements로 변수명 변경
mcodnjs Jan 31, 2024
4a62d4c
refactor: 메서드 위치 변경
mcodnjs Jan 31, 2024
babb205
refactor: 메서드명 변경 및 LikeInfo dto 패키지로 이동
mcodnjs Jan 31, 2024
8530e26
test: LikeService 테스트 추가
mcodnjs Jan 31, 2024
339be7b
test: LikeSyncScheduler 테스트 추가
mcodnjs Jan 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: likeElements로 변수명 변경
mcodnjs committed Jan 31, 2024
commit c658576178db304efdbe666917609eecc326bb4d
Original file line number Diff line number Diff line change
@@ -138,10 +138,10 @@ private Map<Long, LikeInfo> getLikeInfoByTripIds(final Long memberId, final List
}

if (!nonCachedTripIds.isEmpty()) {
final List<LikeElement> likeElementByTripIds = customLikeRepository.findLikeElementByTripIds(nonCachedTripIds);
likeElementByTripIds.addAll(getEmptyLikeElements(likeElementByTripIds, nonCachedTripIds));
likeElementByTripIds.forEach(this::cachingLike);
likeInfoByTrip.putAll(new LikeElements(likeElementByTripIds).toLikeInfo(memberId));
final List<LikeElement> likeElements = customLikeRepository.findLikeElementByTripIds(nonCachedTripIds);
likeElements.addAll(getEmptyLikeElements(likeElements, nonCachedTripIds));
likeElements.forEach(this::cachingLike);
likeInfoByTrip.putAll(new LikeElements(likeElements).toLikeInfo(memberId));
}
return likeInfoByTrip;
}
@@ -159,17 +159,17 @@ private LikeInfo getLikeInfoByTripId(final Long memberId, final Long tripId) {
}

private List<LikeElement> getEmptyLikeElements(
final List<LikeElement> likeElementByTripIds,
final List<LikeElement> likeElements,
final List<Long> nonCachedTripIds
) {
return nonCachedTripIds.stream()
.filter(tripId -> doesNotContainTripId(likeElementByTripIds, tripId))
.filter(tripId -> doesNotContainTripId(likeElements, tripId))
.map(LikeElement::empty)
.toList();
}

private boolean doesNotContainTripId(final List<LikeElement> likeElementByTripIds, final Long tripId) {
return likeElementByTripIds.stream()
private boolean doesNotContainTripId(final List<LikeElement> likeElements, final Long tripId) {
return likeElements.stream()
.noneMatch(likeElement -> likeElement.getTripId().equals(tripId));
}