diff options
Diffstat (limited to 'juick-server/src/main/java/com')
-rw-r--r-- | juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java index c567b5cd..e8c32e77 100644 --- a/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java @@ -26,7 +26,6 @@ import org.springframework.dao.DuplicateKeyException; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; import javax.annotation.Nonnull; import javax.inject.Inject; @@ -113,34 +112,17 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip return Collections.emptyList(); } - @Transactional(readOnly = true) @Override public List<User> getUsersSubscribedToUserRecommendations(final int uid, final int mid, final int muid) { - List<Integer> tags = tagService.getMessageTagsIDs(mid); - - String query = "SELECT s.suser_id FROM subscr_users s WHERE s.user_id = :uid " + - " AND NOT EXISTS (SELECT 1 FROM bl_users b WHERE b.bl_user_id = :muid and b.user_id = s.user_id) " + - " AND NOT EXISTS (SELECT 1 FROM subscr_users s1 WHERE s1.user_id = :muid AND s.user_id = s1.suser_id) " + - " AND NOT EXISTS (SELECT 1 FROM subscr_messages sm WHERE sm.message_id = :mid AND s.user_id = sm.suser_id) " + - " AND NOT EXISTS (SELECT 1 FROM favorites WHERE favorites.message_id = :mid AND favorites.user_id = s.user_id) " + - " AND s.user_id NOT IN (SELECT s2.suser_id FROM subscr_users s2 " + - " INNER JOIN favorites f ON (f.message_id = :mid AND s2.user_id = f.user_id AND f.user_id != :uid))"; - - MapSqlParameterSource sqlParameterSource = new MapSqlParameterSource() - .addValue("uid", uid) - .addValue("muid", muid) - .addValue("mid", mid); - - if (!tags.isEmpty()) { - sqlParameterSource.addValue("ids", tags); - query += " AND NOT EXISTS (SELECT 1 FROM subscr_tags st WHERE st.tag_id IN (:ids) AND s.user_id = st.suser_id) " + - " AND NOT EXISTS (SELECT 1 FROM bl_tags b WHERE b.tag_id IN (:ids) AND s.user_id = b.user_id)"; + Message msg = messagesService.getMessage(mid); + List<String> msgTags = tagService.getMessageTags(mid).stream().map(t -> t.getTag().getName()).collect(Collectors.toList()); + if (msg.getLikes() == 1) { + return userService.getUserReaders(uid).stream() + .filter(u -> !userService.isInBLAny(u.getUid(), muid)) + .filter(u -> Collections.disjoint(tagService.getUserBLTags(u.getUid()), msgTags)) + .collect(Collectors.toList()); } - - List<Integer> userids = getNamedParameterJdbcTemplate().queryForList( - query, sqlParameterSource, Integer.class); - - return userService.getUsersByID(userids); + return Collections.emptyList(); } @Transactional |