aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-08-15 14:30:33 +0300
committerGravatar Vitaly Takmazov2018-08-15 14:30:33 +0300
commite2750a57b9405522102fc6ad083e738f3f389249 (patch)
treed01d2678a93a2ea60a802b5bc14395adeb47e614 /juick-server/src/main/java/com/juick/service
parentf8963d4a127742552e8839c28ce54c38c48eb26d (diff)
Fix recommendations delivery
Diffstat (limited to 'juick-server/src/main/java/com/juick/service')
-rw-r--r--juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java34
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