From b274155e5ecf7809bf40c87a8ab5c7c3656c5345 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Wed, 30 Oct 2024 20:59:56 +0900 Subject: [PATCH] =?UTF-8?q?#561=20[fix]=20Cache=20=EB=8F=99=EC=8B=9C?= =?UTF-8?q?=EC=84=B1=20=EC=9D=B4=EC=8A=88=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moim/domain/popular/MoimCuriousPost.java | 17 +++++++++++++++ .../domain/popular/MoimCuriousWriter.java | 21 +++++++++++++++++-- .../popular/MoimPopularInfoService.java | 1 - 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/module-domain/src/main/java/com/mile/moim/domain/popular/MoimCuriousPost.java b/module-domain/src/main/java/com/mile/moim/domain/popular/MoimCuriousPost.java index f8ab8d24..bdee1b4d 100644 --- a/module-domain/src/main/java/com/mile/moim/domain/popular/MoimCuriousPost.java +++ b/module-domain/src/main/java/com/mile/moim/domain/popular/MoimCuriousPost.java @@ -7,19 +7,24 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.Objects; + @Embeddable @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) public class MoimCuriousPost { + private Long postId; private String title; private String idUrl; private String contents; private String imgUrl; private String topic; private boolean isContainPhoto; + public static MoimCuriousPost of(final Post post) { return new MoimCuriousPost( + post.getId(), post.getTitle(), post.getIdUrl(), post.getContent(), @@ -28,4 +33,16 @@ public static MoimCuriousPost of(final Post post) { post.isContainPhoto() ); } + + @Override + public int hashCode() { + return postId.intValue(); + } + + @Override + public boolean equals(Object target) { + MoimCuriousPost targetPost = (MoimCuriousPost) target; + + return Objects.equals(this.postId, targetPost.postId); + } } diff --git a/module-domain/src/main/java/com/mile/moim/domain/popular/MoimCuriousWriter.java b/module-domain/src/main/java/com/mile/moim/domain/popular/MoimCuriousWriter.java index ca9c3a8e..11c6eb8f 100644 --- a/module-domain/src/main/java/com/mile/moim/domain/popular/MoimCuriousWriter.java +++ b/module-domain/src/main/java/com/mile/moim/domain/popular/MoimCuriousWriter.java @@ -6,17 +6,34 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.Objects; + @Embeddable @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class MoimCuriousWriter { + Long writerNameId; String name; - private MoimCuriousWriter(final String name) { + + private MoimCuriousWriter(final Long writerNameId, final String name) { + this.writerNameId = writerNameId; this.name = name; } public static MoimCuriousWriter of(final WriterName writerName) { - return new MoimCuriousWriter(writerName.getName()); + return new MoimCuriousWriter(writerName.getId(), writerName.getName()); + } + + @Override + public int hashCode() { + return writerNameId.intValue(); + } + + @Override + public boolean equals(Object target) { + MoimCuriousWriter targetWriter = (MoimCuriousWriter) target; + + return Objects.equals(this.name, targetWriter.name) && Objects.equals(this.writerNameId, targetWriter.writerNameId); } } diff --git a/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoService.java b/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoService.java index 38785dfa..f62119fe 100644 --- a/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoService.java +++ b/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoService.java @@ -17,7 +17,6 @@ public class MoimPopularInfoService { @Cacheable(value = "moimPopularInfo", key = "#moim.id") - @AtomicValidateMoimPopulerInfo public MoimPopularInfo getMoimPopularInfo(final Moim moim) { return moimPopularInfoRepository.findByMoimId(moim.getId()).orElseGet( () -> moimPopularInfoRegister.setMostPopularInfoOfMoim(moim)