From dc0b056a71475868c94c946e3333421e9fae35fc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 22 Nov 2023 04:31:05 +0300 Subject: `message_tags` cache --- src/main/java/com/juick/service/SubscriptionServiceImpl.java | 6 +++--- src/main/java/com/juick/service/TagService.java | 5 +++-- src/main/java/com/juick/service/TagServiceImpl.java | 7 ------- 3 files changed, 6 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/juick/service') diff --git a/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/src/main/java/com/juick/service/SubscriptionServiceImpl.java index fae1b824..4aa5b5ac 100644 --- a/src/main/java/com/juick/service/SubscriptionServiceImpl.java +++ b/src/main/java/com/juick/service/SubscriptionServiceImpl.java @@ -62,8 +62,8 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip .filter(u -> !userService.isInBL(u.getUid(), msg.getUser().getUid())) .toList(); List users = ListUtils.union(subscribers, mentionedUsers); - List tags = tagService.getMessageTagsIDs(mid); - List tagsStr = tagService.getMessageTags(mid).stream().map(t -> t.getTag().getName()) + var tags = tagService.getMessageTags(mid); + List tagsStr = tags.stream().map(t -> t.getTag().getName()) .toList(); Set set = users.stream() @@ -80,7 +80,7 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip + " AND NOT EXISTS (SELECT 1 FROM bl_tags bt WHERE bt.tag_id IN (:ids) and st.suser_id = bt.user_id)", new MapSqlParameterSource() - .addValue("ids", tags) + .addValue("ids", tags.stream().map(t -> t.getTag().getId()).collect(Collectors.toList())) .addValue("uid", uid) .addValue("authorUid", author.getUid()), Integer.class); diff --git a/src/main/java/com/juick/service/TagService.java b/src/main/java/com/juick/service/TagService.java index 84bde121..ef937460 100644 --- a/src/main/java/com/juick/service/TagService.java +++ b/src/main/java/com/juick/service/TagService.java @@ -21,6 +21,7 @@ import com.juick.model.Tag; import com.juick.model.User; import com.juick.model.TagStats; import org.apache.commons.lang3.tuple.Pair; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import java.util.Collection; @@ -50,13 +51,13 @@ public interface TagService { List getTagStats(); + @CacheEvict(value = "message_tags", key = "#mid") Set updateTags(int mid, Collection newTags); Pair> fromString(String txt); + @Cacheable(value = "message_tags") List getMessageTags(int mid); - List getMessageTagsIDs(int mid); - boolean blacklistTag(User user, Tag tag); } diff --git a/src/main/java/com/juick/service/TagServiceImpl.java b/src/main/java/com/juick/service/TagServiceImpl.java index c9384f6a..90d0fc83 100644 --- a/src/main/java/com/juick/service/TagServiceImpl.java +++ b/src/main/java/com/juick/service/TagServiceImpl.java @@ -277,13 +277,6 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { }, mid); } - @Override - public List getMessageTagsIDs(final int mid) { - return getJdbcTemplate().queryForList( - "SELECT tag_id FROM messages_tags WHERE message_id = ?", - Integer.class, mid); - } - @Override public boolean blacklistTag(User user, Tag tag) { int rowcount = getNamedParameterJdbcTemplate().update( -- cgit v1.2.3