From c6972c05dcee19afb5725767f755a56f5162aee2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 21 Oct 2021 22:52:14 +0300 Subject: Make popular feed equal to service user recommendations feed to have correct RSS feeds --- .../java/com/juick/service/MessagesService.java | 6 +-- .../com/juick/service/MessagesServiceImpl.java | 52 ++++------------------ src/main/java/com/juick/service/UserService.java | 2 - .../java/com/juick/service/UserServiceImpl.java | 8 ---- 4 files changed, 9 insertions(+), 59 deletions(-) (limited to 'src/main/java/com/juick/service') diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java index bb12a61e..5e3a1e83 100644 --- a/src/main/java/com/juick/service/MessagesService.java +++ b/src/main/java/com/juick/service/MessagesService.java @@ -85,8 +85,6 @@ public interface MessagesService { List getRecommended(int uid, int before); - List getPopular(int visitorUid, int before); - List getPhotos(int visitorUid, int before); List getSearch(User visitor, String search, int page); @@ -97,7 +95,7 @@ public interface MessagesService { List getUserBlogAtDay(int uid, int privacy, int daysback); - List getUserBlogWithRecommendations(int uid, int privacy, int before); + List getUserBlogWithRecommendations(User user, User visitor, int privacy, int before); List getUserRecommendations(int uid, int before); @@ -111,8 +109,6 @@ public interface MessagesService { List getReplies(User user, int mid); - boolean setMessagePopular(int mid, int popular); - boolean setMessagePrivacy(int mid); boolean deleteMessage(int uid, int mid); diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index c2e5d15d..0625716a 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -621,20 +621,6 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ + "ORDER BY f.message_id DESC LIMIT 20", sqlParameterSource, Integer.class); } - @Transactional(readOnly = true) - @Override - public List getPopular(final int visitorUid, final int before) { - SqlParameterSource sqlParameterSource = new MapSqlParameterSource().addValue("vid", visitorUid) - .addValue("before", before); - - return getNamedParameterJdbcTemplate().queryForList("SELECT m.message_id FROM messages m WHERE m.privacy > 0 " - + (before > 0 ? " AND m.message_id < :before " : StringUtils.EMPTY) - + " AND m.popular > 0 AND NOT EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :vid and b.bl_user_id = m.user_id) " - + " AND NOT EXISTS (SELECT 1 FROM bl_tags bt WHERE bt.tag_id IN " - + "(SELECT tag_id FROM messages_tags WHERE message_id = m.message_id) and :vid = bt.user_id)" - + " ORDER BY m.message_id DESC LIMIT 20", sqlParameterSource, Integer.class); - } - @Transactional(readOnly = true) @Override public List getPhotos(final int visitorUid, final int before) { @@ -705,9 +691,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public List getUserBlogWithRecommendations(final int uid, final int privacy, final int before) { - SqlParameterSource sqlParameterSource = new MapSqlParameterSource().addValue("uid", uid) - .addValue("privacy", privacy).addValue("before", before); + public List getUserBlogWithRecommendations(final User user, final User visitor, final int privacy, final int before) { + SqlParameterSource sqlParameterSource = new MapSqlParameterSource() + .addValue("uid", user.getUid()) + .addValue("vid", visitor.getUid()) + .addValue("privacy", privacy).addValue("before", before); return getNamedParameterJdbcTemplate() .queryForList("SELECT message_id FROM " + "(SELECT message_id FROM favorites " + " INNER JOIN users" @@ -716,6 +704,9 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ + " ORDER BY message_id DESC LIMIT 20) as r" + " UNION ALL " + "SELECT message_id FROM " + "(SELECT message_id FROM messages" + " INNER JOIN users" + " ON messages.user_id = users.id" + " WHERE user_id = :uid AND users.banned = 0" + + " AND NOT EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :vid and b.bl_user_id = messages.user_id) " + + " AND NOT EXISTS (SELECT 1 FROM bl_tags bt WHERE bt.tag_id IN " + + "(SELECT tag_id FROM messages_tags WHERE message_id = messages.message_id) and :vid = bt.user_id)" + (before > 0 ? " AND message_id < :before" : StringUtils.EMPTY) + " AND privacy >= :privacy ORDER BY message_id DESC LIMIT 20) as m " + "ORDER BY message_id DESC LIMIT 20", sqlParameterSource, Integer.class); @@ -868,33 +859,6 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ return replies; } - @Transactional - @Override - public boolean setMessagePopular(final int mid, final int popular) { - int ret; - MapSqlParameterSource sqlParameterSource = new MapSqlParameterSource().addValue("mid", mid).addValue("popular", - popular); - - switch (popular) { - case -2: - ret = getNamedParameterJdbcTemplate().update("UPDATE messages SET hidden = 1 WHERE message_id = :mid", - sqlParameterSource); - break; - case -1: - sqlParameterSource.addValue("popular", 0); - default: - ret = getNamedParameterJdbcTemplate() - .update("UPDATE messages SET popular = :popular WHERE message_id = :mid", sqlParameterSource); - break; - } - - if (popular == -1) - ret = getNamedParameterJdbcTemplate().update("INSERT INTO top_ignore_messages VALUES (:mid)", - sqlParameterSource); - - return ret > 0; - } - @Transactional @Override public boolean setMessagePrivacy(final int mid) { diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java index dc879821..c0428169 100644 --- a/src/main/java/com/juick/service/UserService.java +++ b/src/main/java/com/juick/service/UserService.java @@ -131,8 +131,6 @@ public interface UserService { boolean isAdminUser(User user); - boolean isServiceUser(User user); - Optional getTwitterToken(int uid); boolean deleteTwitterToken(Integer uid); diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java index 9762802f..e73f4ea3 100644 --- a/src/main/java/com/juick/service/UserServiceImpl.java +++ b/src/main/java/com/juick/service/UserServiceImpl.java @@ -60,9 +60,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Value("${juick.admin_users:}") List adminUsers; - @Value("${service_user:juick}") - private String serviceUser; - private class UserMapper implements RowMapper { @Override public User mapRow(@Nonnull ResultSet rs, int rowNum) throws SQLException { @@ -669,11 +666,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { public boolean isAdminUser(User user) { return adminUsers.contains(user.getName()); } - - @Override - public boolean isServiceUser(User user) { - return user.getName().equals(serviceUser); - } @Transactional(readOnly = true) @Override -- cgit v1.2.3