diff --git a/src/main/java/in/koreatech/koin/domain/community/article/model/readmodel/ArticleSummary.java b/src/main/java/in/koreatech/koin/domain/community/article/model/readmodel/ArticleSummary.java new file mode 100644 index 000000000..d3473b4c6 --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/community/article/model/readmodel/ArticleSummary.java @@ -0,0 +1,9 @@ +package in.koreatech.koin.domain.community.article.model.readmodel; + +public record ArticleSummary( + Integer id, + Integer boardId, + String 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 924c814e6..109c95a97 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 @@ -20,6 +20,7 @@ import in.koreatech.koin.domain.community.article.exception.BoardNotFoundException; import in.koreatech.koin.domain.community.article.model.Article; import in.koreatech.koin.domain.community.article.model.Board; +import in.koreatech.koin.domain.community.article.model.readmodel.ArticleSummary; import jakarta.persistence.EntityNotFoundException; public interface ArticleRepository extends Repository { @@ -32,6 +33,17 @@ public interface ArticleRepository extends Repository { List
findAllByIdIn(Collection articleIds); + @Query(""" + SELECT new in.koreatech.koin.domain.community.article.model.readmodel.ArticleSummary( + a.id, + a.board.id, + a.title + ) + FROM Article a + WHERE a.id IN :articleIds + """) + List findAllSummariesByIdIn(@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 9e3a11d89..3a477d6f4 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 @@ -15,7 +15,7 @@ import in.koreatech.koin.common.event.KoreatechArticleKeywordEvent; import in.koreatech.koin.domain.community.article.dto.ArticleKeywordResult; -import in.koreatech.koin.domain.community.article.model.Article; +import in.koreatech.koin.domain.community.article.model.readmodel.ArticleSummary; import in.koreatech.koin.domain.community.article.repository.ArticleRepository; import in.koreatech.koin.domain.community.keyword.dto.ArticleKeywordCreateRequest; import in.koreatech.koin.domain.community.keyword.dto.ArticleKeywordResponse; @@ -153,10 +153,10 @@ public ArticleKeywordsSuggestionResponse suggestKeywords(KeywordCategory categor public void sendKeywordNotification(KeywordNotificationRequest request) { Set updateNotificationIds = request.updateNotification(); - List
articles = articleRepository.findAllByIdIn(updateNotificationIds); + List articleSummaries = articleRepository.findAllSummariesByIdIn(updateNotificationIds); - for (Article article : articles) { - List matchedKeywords = keywordExtractor.matchKeywords(article.getTitle(), KeywordCategory.KOREATECH); + for (ArticleSummary articleSummary : articleSummaries) { + List matchedKeywords = keywordExtractor.matchKeywords(articleSummary.title(), KeywordCategory.KOREATECH); if (matchedKeywords.isEmpty()) { continue; } @@ -170,9 +170,9 @@ public void sendKeywordNotification(KeywordNotificationRequest request) { } eventPublisher.publishEvent(KoreatechArticleKeywordEvent.of( - article.getId(), - article.getBoard().getId(), - article.getTitle(), + articleSummary.id(), + articleSummary.boardId(), + articleSummary.title(), keywordByUserId )); }