-
Notifications
You must be signed in to change notification settings - Fork 2
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
118 fea 조회 성능 최적화 및 인기 게더링 조회 #126
Merged
The head ref may contain hidden characters: "118-fea-\uC870\uD68C-\uC131\uB2A5-\uCD5C\uC801\uD654-\uBC0F-\uC778\uAE30-\uAC8C\uB354\uB9C1-\uC870\uD68C"
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
a6e3134
fix : 임시 저장
kcsc2217 b964e49
feat : 게더링 캐싱
kcsc2217 ad0e91b
resolve conflict
kcsc2217 c69c01d
feat : 게더링 생성 시 캐시 비우기
kcsc2217 350a1fe
feat : 포트폴리오 게더링 첫페이지 캐싱
kcsc2217 c9eb7a9
fix: 포트폴리오 첫 페이지만 캐싱
kcsc2217 4827863
Merge branch 'develop' into 118-fea-조회-성능-최적화-및-인기-게더링-조회
kcsc2217 9f228e1
fix: 임시 반영
kcsc2217 30d7664
Merge branch 'develop' into 118-fea-조회-성능-최적화-및-인기-게더링-조회
kcsc2217 85d716e
feat: User 에 복합인덱스 적용
kcsc2217 40207fe
feat: 포트폴리오 첫페이지 캐싱
kcsc2217 e1419a0
feat: 조회 시간순으로 변경
kcsc2217 caf9e1c
feat: 클래스 구조 변경
kcsc2217 4c878e8
feat: Redis Zset을 사용한 조회 성능 최적화
kcsc2217 93d5fc6
refactor: Redis Zset 첫 페이지 조회 성능 최적화 함수 분리
kcsc2217 aa4fdb8
feat: 게시물 저장시 redis 정합성 맞추기
kcsc2217 72aa553
fix: 게더링 서비스와 RedisCleanUp
kcsc2217 b9b7c12
feat: 게더링 수정시 Redis 데이터 정합성 맞추기
kcsc2217 ceb1d6d
feat: 게더링 삭제시 Redis 데이터 정합성 맞추기
kcsc2217 69ae189
feat: enum 타입 다를 시 exception
kcsc2217 b60de55
fix: enum 타입 portfolio 테이블 추가
kcsc2217 dd05046
fix: 코드 리팩터링
kcsc2217 a7a0bab
feat: Redis Set을 이용한 포트폴리오 첫 페이지 캐시
kcsc2217 5dc8a56
feat: 포트폴리오 update 시에 Redis 정합성 맞추기
kcsc2217 1d05a67
fix: 테스트 수정사항
kcsc2217 6959023
fix: 이벤트 걷어내고, zset 에서 List로 변경
kcsc2217 1f85ac1
fix: 포트폴리오 List로 구현
kcsc2217 6806097
fix: 다시 zset 방식으로 변경
kcsc2217 e294482
fix: 포트폴리오 이벤트 걷어냄
kcsc2217 013812d
fix: 의존성 삭제
kcsc2217 a0ffb2f
fix: 업데이트 반영
kcsc2217 b105c80
fix: 테스트 오류 수정
kcsc2217 0067741
complict resolve
kcsc2217 3f30554
fix: 캐싱 테스트 코드 작성
kcsc2217 90cb8a2
fix: 테코 수정
kcsc2217 0f5c312
fix: 캐싱 사이즈 체킹 작업
kcsc2217 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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/palettee/gathering/controller/dto/Response/CustomSliceResponse.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,14 @@ | ||
package com.palettee.gathering.controller.dto.Response; | ||
|
||
import java.util.List; | ||
|
||
public record CustomSliceResponse( | ||
List<GatheringResponse> content, | ||
boolean hasNext, | ||
Long nextId | ||
) { | ||
|
||
public static CustomSliceResponse toDTO(List<GatheringResponse> content, boolean hasNext, Long nextLikeId) { | ||
return new CustomSliceResponse (content, hasNext, nextLikeId); | ||
} | ||
} |
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 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 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
70 changes: 70 additions & 0 deletions
70
src/main/java/com/palettee/gathering/repository/GatheringRedisRepository.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,70 @@ | ||
package com.palettee.gathering.repository; | ||
|
||
import com.palettee.gathering.controller.dto.Response.GatheringResponse; | ||
import com.palettee.gathering.domain.Gathering; | ||
import com.palettee.gathering.service.GatheringService; | ||
import com.palettee.global.redis.utils.TypeConverter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.Set; | ||
|
||
import static com.palettee.global.Const.gathering_Page_Size; | ||
|
||
|
||
@Repository | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class GatheringRedisRepository { | ||
|
||
public final static String RedisConstKey_Gathering = "cache:firstPage:gatherings"; | ||
|
||
private final RedisTemplate<String, GatheringResponse> redisTemplate; | ||
private final GatheringService gatheringService; | ||
|
||
@Transactional(readOnly = true) | ||
public void addGatheringInRedis(Long gatheringId) { | ||
log.info("저장 이벤트"); | ||
Set<GatheringResponse> range = redisTemplate.opsForZSet().range(RedisConstKey_Gathering, 0, -1); | ||
if(!range.isEmpty()){ | ||
Gathering gathering = gatheringService.getGathering(gatheringId); | ||
|
||
if(range.size() == gathering_Page_Size){ | ||
log.info("내부 캐시 삭제"); | ||
//맨 마지막 요소 빼기 즉 score가 가장 낮은애를 빼줌 | ||
redisTemplate.opsForZSet().removeRange(RedisConstKey_Gathering, 0, 0); | ||
} | ||
GatheringResponse gatheringResponse = GatheringResponse.toDto(gathering); | ||
redisTemplate.opsForZSet().add(RedisConstKey_Gathering, gatheringResponse, TypeConverter.LocalDateTimeToDouble(gatheringResponse.createDateTime())); | ||
} | ||
|
||
} | ||
|
||
@Transactional(readOnly = true) | ||
public void updateGatheringInRedis(Long gatheringId){ | ||
log.info("수정 이벤트"); | ||
Set<String> keys = redisTemplate.keys(RedisConstKey_Gathering); | ||
|
||
if(!keys.isEmpty()){ | ||
Gathering gathering = gatheringService.getGathering(gatheringId); | ||
|
||
GatheringResponse gatheringResponse = GatheringResponse.toDto(gathering); | ||
|
||
Double score = TypeConverter.LocalDateTimeToDouble(gatheringResponse.createDateTime()); | ||
|
||
Long removeCount = redisTemplate.opsForZSet().removeRangeByScore(RedisConstKey_Gathering, score, score); | ||
|
||
if(removeCount != 0){ | ||
log.info("캐시 수정으로 인한 새로운 값 재캐싱"); | ||
redisTemplate.opsForZSet().add(RedisConstKey_Gathering, gatheringResponse, TypeConverter.LocalDateTimeToDouble(gatheringResponse.createDateTime())); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/palettee/gathering/repository/GatheringRepositoryCustom.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
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.
마지막 데이터 빼고 새로운 데이터를 ZSet에 넣는 로직인 것 같아요!! 다만 Redis 안에 데이터수가 pageable size 보다 적을 때에는 마지막 데이터를 삭제하면 안될 것 같아요!