diff --git a/src/main/java/in/koreatech/koin/domain/community/article/dto/ArticleSummary.java b/src/main/java/in/koreatech/koin/domain/community/article/dto/ArticleSummary.java new file mode 100644 index 000000000..0de39a2e1 --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/community/article/dto/ArticleSummary.java @@ -0,0 +1,10 @@ +package in.koreatech.koin.domain.community.article.dto; + +public record ArticleSummary( + Integer id, + String title +) { + public static ArticleSummary of(Integer id, String title) { + return new ArticleSummary(id, title); + } +} diff --git a/src/main/java/in/koreatech/koin/domain/community/article/repository/ArticleRepository.java b/src/main/java/in/koreatech/koin/domain/community/article/repository/ArticleRepository.java index f0e6f4055..0a8b3e1c7 100644 --- a/src/main/java/in/koreatech/koin/domain/community/article/repository/ArticleRepository.java +++ b/src/main/java/in/koreatech/koin/domain/community/article/repository/ArticleRepository.java @@ -15,6 +15,7 @@ import org.springframework.data.repository.Repository; import org.springframework.data.repository.query.Param; +import in.koreatech.koin.domain.community.article.dto.ArticleSummary; import in.koreatech.koin.domain.community.article.exception.ArticleNotFoundException; import in.koreatech.koin.domain.community.article.exception.BoardNotFoundException; import in.koreatech.koin.domain.community.article.model.Article; @@ -31,6 +32,13 @@ public interface ArticleRepository extends Repository { List
findAllByIdIn(Collection articleIds); + @Query(value = """ + SELECT new in.koreatech.koin.domain.community.article.dto.ArticleSummary(a.id, a.title) + FROM Article a + WHERE a.id IN :articleIds + """) + List findAllSummaryByIdIn(@Param("articleIds") Collection articleIds); + Page
findAll(Pageable pageable); Page
findAllByBoardIdNot(Integer boardId, PageRequest pageRequest); diff --git a/src/main/java/in/koreatech/koin/domain/community/keyword/service/KeywordService.java b/src/main/java/in/koreatech/koin/domain/community/keyword/service/KeywordService.java index 544312574..91975a7eb 100644 --- a/src/main/java/in/koreatech/koin/domain/community/keyword/service/KeywordService.java +++ b/src/main/java/in/koreatech/koin/domain/community/keyword/service/KeywordService.java @@ -13,6 +13,7 @@ import in.koreatech.koin.common.event.ArticleKeywordEvent; import in.koreatech.koin.domain.community.article.dto.ArticleKeywordResult; +import in.koreatech.koin.domain.community.article.dto.ArticleSummary; import in.koreatech.koin.domain.community.article.model.Article; import in.koreatech.koin.domain.community.article.repository.ArticleRepository; import in.koreatech.koin.domain.community.keyword.dto.ArticleKeywordCreateRequest; @@ -150,8 +151,8 @@ public void sendKeywordNotification(KeywordNotificationRequest request) { return; } - List
articles = articleRepository.findAllByIdIn(request.updateNotification()); - List keywordEvents = keywordExtractor.matchKeyword(articles, null); + List articleSummaries = articleRepository.findAllSummaryByIdIn(request.updateNotification()); + List keywordEvents = keywordExtractor.matchKeyword(articleSummaries, null); for (ArticleKeywordEvent event : keywordEvents) { eventPublisher.publishEvent(event); } diff --git a/src/main/java/in/koreatech/koin/domain/community/util/KeywordExtractor.java b/src/main/java/in/koreatech/koin/domain/community/util/KeywordExtractor.java index 87a7516b2..1804eaf6a 100644 --- a/src/main/java/in/koreatech/koin/domain/community/util/KeywordExtractor.java +++ b/src/main/java/in/koreatech/koin/domain/community/util/KeywordExtractor.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Component; -import in.koreatech.koin.domain.community.article.model.Article; +import in.koreatech.koin.domain.community.article.dto.ArticleSummary; import in.koreatech.koin.domain.community.keyword.model.ArticleKeywordUserMap; import in.koreatech.koin.domain.community.keyword.model.KeywordMatchResult; @@ -15,14 +15,14 @@ public class KeywordExtractor { public List matchKeyword( - List
articles, List articleKeywordUserMaps, Integer authorId + List articleSummaries, List articleKeywordUserMaps, Integer authorId ) { Set keywordMatchResults = new HashSet<>(); - for (Article article : articles) { + for (ArticleSummary articleSummary : articleSummaries) { for (ArticleKeywordUserMap articleKeywordUserMap : articleKeywordUserMaps) { - if (isMatchable(article, articleKeywordUserMap, authorId)) { - addOrUpdateResult(keywordMatchResults, article, articleKeywordUserMap); + if (isMatchable(articleSummary, articleKeywordUserMap, authorId)) { + addOrUpdateResult(keywordMatchResults, articleSummary, articleKeywordUserMap); } } } @@ -30,16 +30,19 @@ public List matchKeyword( return keywordMatchResults.stream().toList(); } - private boolean isMatchable(Article article, ArticleKeywordUserMap articleKeywordUserMap, Integer authorId) { + private boolean isMatchable( + ArticleSummary articleSummaries, ArticleKeywordUserMap articleKeywordUserMap, Integer authorId + ) { return !Objects.equals(articleKeywordUserMap.getUserId(), authorId) - && article.getTitle().contains(articleKeywordUserMap.getKeyword()); + && articleSummaries.title().contains(articleKeywordUserMap.getKeyword()); } private void addOrUpdateResult( - Set keywordMatchResults, Article article, ArticleKeywordUserMap articleKeywordUserMap + Set keywordMatchResults, ArticleSummary ArticleSummary, + ArticleKeywordUserMap articleKeywordUserMap ) { KeywordMatchResult keywordMatchResult = KeywordMatchResult.of( - article.getId(), articleKeywordUserMap.getUserId(), articleKeywordUserMap.getKeyword() + ArticleSummary.id(), articleKeywordUserMap.getUserId(), articleKeywordUserMap.getKeyword() ); keywordMatchResults.stream()