-
Notifications
You must be signed in to change notification settings - Fork 1
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
refactor: 많이 조회한 게시글 키워드 구조 변경 #1061
base: develop
Are you sure you want to change the base?
refactor: 많이 조회한 게시글 키워드 구조 변경 #1061
Conversation
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.
연관 이슈가 잘못 연결되어 있는 것 같아요~
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.
고생하셨습니다!
@Component | ||
@RequiredArgsConstructor | ||
public class KeywordRankingManager { | ||
|
||
private final PopularKeywordTracker popularKeywordTracker; | ||
private final ArticleSearchKeywordRepository keywordRepository; | ||
|
||
public List<String> getTopKeywords(int count) { | ||
List<String> primaryKeywords = new ArrayList<>(popularKeywordTracker.getTopKeywords(count)); | ||
|
||
if (primaryKeywords.size() < count) { | ||
int remainingCount = count - primaryKeywords.size(); | ||
List<String> secondaryKeywords = getBackupKeywords(remainingCount); | ||
secondaryKeywords.stream() | ||
.filter(keyword -> !primaryKeywords.contains(keyword)) | ||
.forEach(primaryKeywords::add); | ||
} | ||
|
||
return primaryKeywords; | ||
} | ||
|
||
private List<String> getBackupKeywords(int count) { | ||
LocalDateTime fromDate = LocalDateTime.now().minusWeeks(1); | ||
Pageable pageable = PageRequest.of(0, count); | ||
|
||
List<String> topKeywords = keywordRepository.findTopKeywords(fromDate, pageable); | ||
if (topKeywords.isEmpty()) { | ||
topKeywords = keywordRepository.findTopKeywordsByLatest(pageable); | ||
} | ||
return topKeywords; | ||
} |
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.
클래스 갯수가 늘어나더라도 크기를 작게 분리하는 것이 유지보수에 많은 도움이 된다고 생각합니다. 👍
🔥 연관 이슈
🚀 작업 내용
💬 리뷰 중점사항