diff options
author | Vitaly Takmazov | 2023-11-22 04:31:05 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-11-23 00:28:54 +0300 |
commit | dc0b056a71475868c94c946e3333421e9fae35fc (patch) | |
tree | b0621d6eaa4ed9e4f55160162f277be9babd0145 /src/main/java/com/juick/service | |
parent | 4a970162d39eedadd055a69f3f77010460c21fcc (diff) |
`message_tags` cache
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r-- | src/main/java/com/juick/service/SubscriptionServiceImpl.java | 6 | ||||
-rw-r--r-- | src/main/java/com/juick/service/TagService.java | 5 | ||||
-rw-r--r-- | src/main/java/com/juick/service/TagServiceImpl.java | 7 |
3 files changed, 6 insertions, 12 deletions
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<User> users = ListUtils.union(subscribers, mentionedUsers); - List<Integer> tags = tagService.getMessageTagsIDs(mid); - List<String> tagsStr = tagService.getMessageTags(mid).stream().map(t -> t.getTag().getName()) + var tags = tagService.getMessageTags(mid); + List<String> tagsStr = tags.stream().map(t -> t.getTag().getName()) .toList(); Set<Integer> 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<TagStats> getTagStats(); + @CacheEvict(value = "message_tags", key = "#mid") Set<Tag> updateTags(int mid, Collection<Tag> newTags); Pair<String, Set<Tag>> fromString(String txt); + @Cacheable(value = "message_tags") List<TagStats> getMessageTags(int mid); - List<Integer> 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 @@ -278,13 +278,6 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { } @Override - public List<Integer> 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( "DELETE FROM bl_tags WHERE tag_id = :tid AND user_id = :uid", |