aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2021-10-25 01:24:37 +0300
committerGravatar Vitaly Takmazov2021-10-25 01:24:37 +0300
commit2cbaa2dd212bb81d34e7b52eff4d03e4780d02de (patch)
tree8b9da98161e4b2ec3d042233f08bbd219bd7a7d4 /src
parent1bca4586c8358ce7cef302c6019f112100b34393 (diff)
Fix top candidates query and update tests
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/service/MessagesService.java6
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java4
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java7
3 files changed, 15 insertions, 2 deletions
diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java
index 5e3a1e83..188a81c0 100644
--- a/src/main/java/com/juick/service/MessagesService.java
+++ b/src/main/java/com/juick/service/MessagesService.java
@@ -83,6 +83,12 @@ public interface MessagesService {
List<Integer> getDiscussions(int uid, Long to);
+ /**
+ * Get messages recommended by friends
+ * @param uid visitor id
+ * @param before
+ * @return recommended message ids
+ */
List<Integer> getRecommended(int uid, int before);
List<Integer> getPhotos(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 eb953586..3bb58a17 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -969,11 +969,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
public List<Integer> getPopularCandidates() {
return getJdbcTemplate().queryForList("SELECT replies.message_id FROM replies "
+ "INNER JOIN messages ON replies.message_id = messages.message_id "
- + "INNER JOIN favorites ON favorites.message_id = messages.message_id "
+ + "LEFT JOIN favorites ON favorites.message_id = messages.message_id "
+ "LEFT JOIN messages_tags ON messages_tags.message_id = messages.message_id "
+ "WHERE COALESCE(messages_tags.tag_id, 0) != 2 "
+ "AND COALESCE(messages_tags.tag_id, 0) != 805 AND replies.ts > TIMESTAMPADD(HOUR, -2, CURRENT_TIMESTAMP) "
- + "AND favorites.user_id != 2 GROUP BY messages.message_id having COUNT(DISTINCT(replies.user_id)) > 5 "
+ + "AND COALESCE(favorites.user_id, 0) != 2 GROUP BY messages.message_id having COUNT(DISTINCT(replies.user_id)) > 5 "
+ "UNION ALL SELECT favorites.message_id FROM favorites "
+ "INNER JOIN messages ON messages.message_id = favorites.message_id "
+ "LEFT JOIN messages_tags ON messages_tags.message_id = messages.message_id "
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 267ab9f8..14517a60 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -805,6 +805,13 @@ public class ServerTests {
assertThat(messagesService.getPopularCandidates().isEmpty(), is(true));
tagService.updateTags(topmid, Collections.singletonList(juickTag));
assertThat(messagesService.getPopularCandidates().isEmpty(), is(false));
+ CommandResult resultRecommend = commandsManager.commandRecommend(serviceUser, URI.create(""), String.valueOf(topmid));
+ List<Integer> msgs = messagesService.getUserRecommendations(serviceUser.getUid(), 0);
+ assertThat(msgs.get(0), is(topmid));
+ List<Integer> allMsgs = messagesService.getUserBlogWithRecommendations(serviceUser, ugnich, 0, 0);
+ assertThat(allMsgs.contains(topmid), is(true));
+ CommandResult resultUndo = commandsManager.commandRecommend(serviceUser, URI.create(""), String.valueOf(topmid));
+ assertThat(messagesService.getPopularCandidates().isEmpty(), is(false));
jdbcTemplate.update("INSERT INTO tags(tag_id, name) VALUES(805, 'NSFW')");
Tag nsfw = tagService.getTag("NSFW", false);
assertThat(nsfw.TID, equalTo(805));