-
Notifications
You must be signed in to change notification settings - Fork 0
미리 배포 #80
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
미리 배포 #80
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,30 +24,60 @@ public class CourseRankingService { | |
| private static final EnumSet<Category> LIBERAL_CATEGORIES = | ||
| EnumSet.complementOf(MAJOR_CATEGORIES); | ||
|
|
||
| // ✅ 교양 랭킹에서 제외할 키워드 | ||
| private static final List<String> LIBERAL_EXCLUDE_KEYWORDS = | ||
| List.of("공동체리더십훈련", "채플"); | ||
|
|
||
| public CourseRankingService(CourseRankingRepository repository) { | ||
| this.repository = repository; | ||
| } | ||
|
|
||
| public RankingResponse getCourseRanking() { | ||
| return new RankingResponse( | ||
| loadTop10(MAJOR_CATEGORIES), | ||
| loadTop10(LIBERAL_CATEGORIES) | ||
| loadTop10(MAJOR_CATEGORIES, false), | ||
| loadTop10(LIBERAL_CATEGORIES, true) | ||
| ); | ||
| } | ||
|
|
||
| private List<RankingItem> loadTop10(Set<Category> categories) { | ||
| var rows = repository.findTopCoursesByCategories( | ||
| private List<RankingItem> loadTop10(Set<Category> categories, boolean applyLiberalFilter) { | ||
| int fetchSize = applyLiberalFilter ? 30 : 10; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| var fetchedRows = repository.findTopCoursesByCategories( | ||
| categories, | ||
| PageRequest.of(0, 10) | ||
| PageRequest.of(0, fetchSize) | ||
| ); | ||
|
|
||
| return IntStream.range(0, rows.size()) | ||
| // ✅ 여기서 최종 리스트를 한 번만 결정 | ||
| final List<? extends CourseRankingRepository.CourseCountRow> finalRows; | ||
|
|
||
| if (applyLiberalFilter) { | ||
| finalRows = fetchedRows.stream() | ||
| .filter(r -> !containsAny(r.getName(), LIBERAL_EXCLUDE_KEYWORDS)) | ||
| .limit(10) | ||
| .toList(); | ||
| } else { | ||
| finalRows = fetchedRows.stream() | ||
| .limit(10) | ||
| .toList(); | ||
| } | ||
|
Comment on lines
+51
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Stream<? extends CourseRankingRepository.CourseCountRow> stream = fetchedRows.stream();
if (applyLiberalFilter) {
stream = stream.filter(r -> !containsAny(r.getName(), LIBERAL_EXCLUDE_KEYWORDS));
}
final List<? extends CourseRankingRepository.CourseCountRow> finalRows = stream.limit(10).toList(); |
||
|
|
||
| // ✅ finalRows는 effectively final → 람다에서 안전 | ||
| return IntStream.range(0, finalRows.size()) | ||
| .mapToObj(i -> new RankingItem( | ||
| i + 1, | ||
| rows.get(i).getName(), | ||
| rows.get(i).getTakenCount(), | ||
| finalRows.get(i).getName(), | ||
| finalRows.get(i).getTakenCount(), | ||
| 0 | ||
| )) | ||
| .toList(); | ||
| } | ||
|
|
||
|
|
||
| private boolean containsAny(String text, List<String> keywords) { | ||
| if (text == null) return false; | ||
| for (String kw : keywords) { | ||
| if (text.contains(kw)) return true; | ||
| } | ||
| return false; | ||
| } | ||
|
Comment on lines
+76
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
스타일 가이드(규칙 66)에 따라 읽기 전용(read-only) 트랜잭션에는
@Transactional(readOnly = true)를 명시하는 것이 좋습니다. 이 어노테이션은 JPA에게 성능 최적화를 할 수 있다는 힌트를 주어 데이터베이스 부하를 줄일 수 있습니다.getCourseRanking메서드는 데이터를 조회만 하므로 이 어노테이션을 추가하는 것을 권장합니다. FQCN(정규화된 클래스 이름)을 사용하면 import 문을 추가하지 않고도 적용할 수 있습니다.References