aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java9
-rw-r--r--src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java4
-rw-r--r--src/main/java/com/juick/service/SubscriptionServiceImpl.java4
-rw-r--r--src/main/java/com/juick/service/TagServiceImpl.java26
4 files changed, 23 insertions, 20 deletions
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index 790e695e..4247cee5 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -153,7 +153,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setInt(1, mid);
- ps.setInt(2, newTags.get(i).TID);
+ ps.setInt(2, newTags.get(i).getId());
}
@Override
@@ -1032,13 +1032,14 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Override
public List<Integer> getPopularCandidates() {
var beforeTime = Instant.now().minus(2, ChronoUnit.HOURS);
+ var nsfw = tagService.getTag("NSFW", true);
var sql = """
SELECT replies.message_id FROM replies
INNER JOIN messages ON replies.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 > :before
+ AND COALESCE(messages_tags.tag_id, 0) != :nsfw_id AND replies.ts > :before
AND NOT EXISTS (SELECT 1 FROM favorites WHERE message_id = messages.message_id
AND user_id = 2) GROUP BY replies.message_id HAVING COUNT(DISTINCT(replies.user_id)) > 5
UNION ALL SELECT favorites.message_id FROM favorites
@@ -1051,7 +1052,9 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
GROUP BY favorites.message_id HAVING COUNT(DISTINCT favorites.user_id) > 2
""";
return getNamedParameterJdbcTemplate().queryForList(sql, new MapSqlParameterSource()
- .addValue("before", beforeTime.atOffset(ZoneOffset.UTC), java.sql.Types.TIMESTAMP_WITH_TIMEZONE),
+ .addValue("nsfw_id", nsfw.getId())
+ .addValue("before", beforeTime.atOffset(ZoneOffset.UTC),
+ java.sql.Types.TIMESTAMP_WITH_TIMEZONE),
Integer.class);
}
diff --git a/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java b/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java
index e13b54fc..437c9f8c 100644
--- a/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java
+++ b/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java
@@ -49,14 +49,14 @@ public class PrivacyQueriesServiceImpl extends BaseJdbcService implements Privac
public PrivacyResult blacklistTag(final User user, final Tag tag) {
int result = getJdbcTemplate().update(
"DELETE FROM bl_tags WHERE user_id = ? AND tag_id = ?",
- user.getUid(), tag.TID);
+ user.getUid(), tag.getId());
if (result > 0)
return PrivacyResult.Removed;
getJdbcTemplate().update(
"INSERT INTO bl_tags(user_id, tag_id) VALUES (?, ?)",
- user.getUid(), tag.TID);
+ user.getUid(), tag.getId());
return PrivacyResult.Added;
}
diff --git a/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/src/main/java/com/juick/service/SubscriptionServiceImpl.java
index bf7d1045..fae1b824 100644
--- a/src/main/java/com/juick/service/SubscriptionServiceImpl.java
+++ b/src/main/java/com/juick/service/SubscriptionServiceImpl.java
@@ -175,7 +175,7 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip
try {
return getJdbcTemplate().update(
- "INSERT INTO subscr_tags(tag_id,suser_id) VALUES (?,?)", toTag.TID,
+ "INSERT INTO subscr_tags(tag_id,suser_id) VALUES (?,?)", toTag.getId(),
user.getUid()) == 1;
} catch (DuplicateKeyException e) {
return true;
@@ -186,7 +186,7 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip
@Override
public boolean unSubscribeTag(final User user, final Tag toTag) {
return getJdbcTemplate().update(
- "DELETE FROM subscr_tags WHERE tag_id=? AND suser_id=?", toTag.TID, user.getUid()) > 0;
+ "DELETE FROM subscr_tags WHERE tag_id=? AND suser_id=?", toTag.getId(), user.getUid()) > 0;
}
@Transactional(readOnly = true)
diff --git a/src/main/java/com/juick/service/TagServiceImpl.java b/src/main/java/com/juick/service/TagServiceImpl.java
index 1f77eb81..f15fd113 100644
--- a/src/main/java/com/juick/service/TagServiceImpl.java
+++ b/src/main/java/com/juick/service/TagServiceImpl.java
@@ -60,8 +60,8 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
"SELECT synonym_id,name FROM tags WHERE tag_id=?",
(rs, num) -> {
Tag ret = new Tag(rs.getString(2));
- ret.TID = tid;
- ret.SynonymID = rs.getInt(1);
+ ret.setId(tid);
+ ret.setSynonymId(rs.getInt(1));
return ret;
},
tid);
@@ -79,8 +79,8 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
"SELECT tag_id, synonym_id, name FROM tags WHERE name = ?",
(rs, rowNum) -> {
Tag ret1 = new Tag(rs.getString(3));
- ret1.TID = rs.getInt(1);
- ret1.SynonymID = rs.getInt(2);
+ ret1.setId(rs.getInt(1));
+ ret1.setSynonymId(rs.getInt(2));
return ret1;
},
tag);
@@ -89,7 +89,7 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
if (ret == null && autoCreate) {
ret = new Tag(tag);
- ret.TID = createTag(tag);
+ ret.setId(createTag(tag));
}
return ret;
@@ -199,7 +199,7 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
List<Integer> idsForDelete = newTags.stream()
.filter(currentTags::contains)
- .map(tag -> tag.TID)
+ .map(Tag::getId)
.toList();
if (newTags.size() - idsForDelete.size() >= 5) {
return currentTags;
@@ -216,7 +216,7 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setInt(1, mid);
- ps.setInt(2, addedTags.get(i).TID);
+ ps.setInt(2, addedTags.get(i).getId());
}
@Override
@@ -248,8 +248,8 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
"INNER JOIN messages_tags ON (messages_tags.message_id = ? AND messages_tags.tag_id = tags.tag_id)",
(rs, num) -> {
Tag t = new Tag(rs.getString(3));
- t.TID = rs.getInt(1);
- t.SynonymID = rs.getInt(2);
+ t.setId(rs.getInt(1));
+ t.setSynonymId(rs.getInt(2));
TagStats s = new TagStats();
s.setTag(t);
s.setUsageCount(rs.getInt(4));
@@ -269,10 +269,10 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
public boolean blacklistTag(User user, Tag tag) {
int rowcount = getNamedParameterJdbcTemplate().update(
"DELETE FROM bl_tags WHERE tag_id = :tid AND user_id = :uid",
- new MapSqlParameterSource().addValue("tid", tag.TID).addValue("uid", user.getUid()));
+ new MapSqlParameterSource().addValue("tid", tag.getId()).addValue("uid", user.getUid()));
return rowcount <= 0 && getNamedParameterJdbcTemplate()
.update("INSERT INTO bl_tags(user_id, tag_id) VALUES(:uid,:tid)",
- new MapSqlParameterSource().addValue("tid", tag.TID)
+ new MapSqlParameterSource().addValue("tid", tag.getId())
.addValue("uid", user.getUid())) > 0;
}
@@ -281,7 +281,7 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
public boolean isInBL(User user, Tag tag) {
List<Integer> list = getJdbcTemplate().queryForList(
"SELECT 1 FROM bl_tags WHERE user_id = ? AND tag_id = ?",
- Integer.class, user.getUid(), tag.TID);
+ Integer.class, user.getUid(), tag.getId());
return !list.isEmpty() && list.get(0) == 1;
}
@@ -290,7 +290,7 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
public boolean isSubscribed(User user, Tag tag) {
List<Integer> list = getJdbcTemplate().queryForList(
"SELECT 1 FROM subscr_tags WHERE suser_id = ? AND tag_id = ?",
- Integer.class, user.getUid(), tag.TID);
+ Integer.class, user.getUid(), tag.getId());
return !list.isEmpty() && list.get(0) == 1;
}