diff options
author | Vitaly Takmazov | 2023-12-08 14:26:43 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-12-08 14:26:43 +0300 |
commit | 70810eb92ff7810eb0df133d157078064d666a33 (patch) | |
tree | 34cdd37cecc600751862a0c8229ec5650b0ff80b /src/main/java/com/juick/service | |
parent | 45733cbe5a0d247c017c37a82be24efc7d7b9db7 (diff) |
Do not count recommendations from banned users
* Previosly only own message recommendations were filtered, now all message recommendations filter banned users
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r-- | src/main/java/com/juick/service/MessagesService.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/service/MessagesServiceImpl.java | 10 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java index 5574dbbf..6f262dd7 100644 --- a/src/main/java/com/juick/service/MessagesService.java +++ b/src/main/java/com/juick/service/MessagesService.java @@ -76,7 +76,7 @@ public interface MessagesService { Message getReplyByUri(String replyUri); - List<Pair<Integer, User>> getMessagesRecommendations(Collection<Integer> mids); + List<Pair<Integer, User>> getMessagesRecommendations(int visitorUid, Collection<Integer> mids); @Cacheable(value = "discover", key="{ #visitorUid, #before }") List<Integer> getAll(int visitorUid, int before); diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index 78197a0f..8292f4fd 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -490,16 +490,18 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public List<Pair<Integer, User>> getMessagesRecommendations(final Collection<Integer> mids) { + public List<Pair<Integer, User>> getMessagesRecommendations(final int visitorUid, final Collection<Integer> mids) { return getNamedParameterJdbcTemplate().query( "SELECT DISTINCT favorites.message_id, users.id, users.nick, favorites.user_uri FROM favorites " + "INNER JOIN users ON (favorites.user_id = users.id) " + "INNER JOIN messages m ON favorites.message_id=m.message_id WHERE favorites.like_id=1 " + "AND NOT EXISTS (SELECT 1 FROM bl_users WHERE " + "(user_id = favorites.user_id AND bl_user_id = m.user_id) " - + "OR (user_id = m.user_id AND bl_user_id = favorites.user_id)) " + + "OR (user_id = m.user_id AND bl_user_id = favorites.user_id) " + + (visitorUid > 0 ? " OR (user_id = :visitorUid AND favorites.user_id = bl_user_id)" : "") + + ") " + "AND favorites.message_id IN (:mids)", - new MapSqlParameterSource("mids", mids), (rs, rowNum) -> { + new MapSqlParameterSource("mids", mids).addValue("visitorUid", visitorUid), (rs, rowNum) -> { User user = new User(); user.setUid(rs.getInt(2)); user.setName(rs.getString(3)); @@ -824,7 +826,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ msgs.forEach(i -> i.setReactions(likes.get(i.getMid()))); msgs.sort(Comparator.comparing(item -> mids.indexOf(item.getMid()))); msgs.forEach(i -> i.setEntities(MessageUtils.getEntities(i))); - List<Pair<Integer, User>> allRecommendations = getMessagesRecommendations(mids); + List<Pair<Integer, User>> allRecommendations = getMessagesRecommendations(uid, mids); msgs.forEach(m -> { m.setRecommendations(new HashSet<>(allRecommendations.stream() .filter(r -> r.getLeft().equals(m.getMid())).map(Pair::getRight).toList())); |