-
Notifications
You must be signed in to change notification settings - Fork 1
fix: 웹사이트 동아리 import 품질 검증 및 통계 캐시 추가 #667
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
Merged
+384
−5
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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/gg/agit/konect/domain/website/service/WebsiteClubStatsReader.java
This file contains hidden or 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 gg.agit.konect.domain.website.service; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.github.benmanes.caffeine.cache.Cache; | ||
| import com.github.benmanes.caffeine.cache.Caffeine; | ||
|
|
||
| import gg.agit.konect.domain.club.enums.ClubCategory; | ||
| import gg.agit.konect.domain.website.repository.WebsiteQueryRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class WebsiteClubStatsReader { | ||
|
|
||
| private static final long UNIVERSITY_CLUB_COUNT_CACHE_MAX_SIZE = 500; | ||
| private static final long CATEGORY_COUNT_CACHE_MAX_SIZE = 10_000; | ||
| private static final Duration CACHE_TTL = Duration.ofMinutes(10); | ||
|
|
||
| private final WebsiteQueryRepository websiteQueryRepository; | ||
| private final Cache<Integer, Long> universityClubCountCache = Caffeine.newBuilder() | ||
| .maximumSize(UNIVERSITY_CLUB_COUNT_CACHE_MAX_SIZE) | ||
| .expireAfterWrite(CACHE_TTL) | ||
| .build(); | ||
| private final Cache<CategoryCountCacheKey, Map<ClubCategory, Long>> categoryCountCache = Caffeine.newBuilder() | ||
| .maximumSize(CATEGORY_COUNT_CACHE_MAX_SIZE) | ||
| .expireAfterWrite(CACHE_TTL) | ||
| .build(); | ||
|
|
||
| public Long getUniversityClubCount(Integer universityId) { | ||
| return universityClubCountCache.get( | ||
| universityId, | ||
| websiteQueryRepository::countClubsByUniversityId | ||
| ); | ||
| } | ||
|
|
||
| public Map<ClubCategory, Long> getCategoryCounts(Integer universityId, String query) { | ||
| CategoryCountCacheKey key = new CategoryCountCacheKey(universityId, normalizeQuery(query)); | ||
| return categoryCountCache.get( | ||
| key, | ||
| cacheKey -> Map.copyOf(websiteQueryRepository.countClubCategories( | ||
| cacheKey.universityId(), | ||
| cacheKey.query() | ||
| )) | ||
| ); | ||
| } | ||
|
|
||
| public void invalidateUniversity(Integer universityId) { | ||
| universityClubCountCache.invalidate(universityId); | ||
| categoryCountCache.asMap().keySet().removeIf(key -> key.universityId().equals(universityId)); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // null/blank queries share one "no search" cache key; trim and Locale.ROOT keep query keys stable. | ||
| private String normalizeQuery(String query) { | ||
| if (query == null || query.isBlank()) { | ||
| return null; | ||
| } | ||
| return query.trim().toLowerCase(Locale.ROOT); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| private record CategoryCountCacheKey( | ||
| Integer universityId, | ||
| String query | ||
| ) { | ||
| } | ||
| } | ||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.