From 22aaf28c779725962a3ebec3e689bef35fe05085 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 3 Feb 2023 02:13:17 +0300 Subject: GetTagNoIndex -> tag.isNotIndexed --- src/main/java/com/juick/model/Tag.java | 16 +++++++ src/main/java/com/juick/service/TagService.java | 2 - .../java/com/juick/service/TagServiceImpl.java | 55 ++++++++++------------ src/main/java/com/juick/www/controllers/Site.java | 6 +-- 4 files changed, 42 insertions(+), 37 deletions(-) (limited to 'src/main/java/com/juick') diff --git a/src/main/java/com/juick/model/Tag.java b/src/main/java/com/juick/model/Tag.java index b27fe7e6..64469a69 100644 --- a/src/main/java/com/juick/model/Tag.java +++ b/src/main/java/com/juick/model/Tag.java @@ -41,6 +41,10 @@ public class Tag implements Comparable, Serializable { private int id; @XmlTransient private int synonymId; + @XmlTransient + private boolean noindex; + @XmlTransient + private boolean notop; public Tag() { // required for (de)serialization @@ -92,4 +96,16 @@ public class Tag implements Comparable, Serializable { public void setSynonymId(int synonymId) { this.synonymId = synonymId; } + public boolean isNotIndexed() { + return noindex; + } + public void setNotIndexed(boolean noindex) { + this.noindex = noindex; + } + public boolean isHiddenFromTop() { + return notop; + } + public void setHiddenFromTop(boolean notop) { + this.notop = notop; + } } diff --git a/src/main/java/com/juick/service/TagService.java b/src/main/java/com/juick/service/TagService.java index d04aacbc..0701bedf 100644 --- a/src/main/java/com/juick/service/TagService.java +++ b/src/main/java/com/juick/service/TagService.java @@ -38,8 +38,6 @@ public interface TagService { List getTags(Stream tags, boolean autoCreate); - boolean getTagNoIndex(int tagId); - int createTag(String name); List getUserTagStats(int uid); diff --git a/src/main/java/com/juick/service/TagServiceImpl.java b/src/main/java/com/juick/service/TagServiceImpl.java index ef5f6e84..0d040273 100644 --- a/src/main/java/com/juick/service/TagServiceImpl.java +++ b/src/main/java/com/juick/service/TagServiceImpl.java @@ -49,17 +49,24 @@ import java.util.stream.Stream; @Repository public class TagServiceImpl extends BaseJdbcService implements TagService { + private class TagMapper implements RowMapper { + @Override + public Tag mapRow(ResultSet rs, int rowNum) throws SQLException { + Tag tag = new Tag(rs.getString(3)); + tag.setId(rs.getInt(1)); + tag.setSynonymId(rs.getInt(2)); + tag.setNotIndexed(rs.getInt("noindex") > 0); + tag.setHiddenFromTop(rs.getInt("notop") > 0); + return tag; + } + } + @Transactional(readOnly = true) @Override public Tag getTag(final int tid) { List list = getJdbcTemplate().query( - "SELECT synonym_id,name FROM tags WHERE tag_id=?", - (rs, num) -> { - Tag ret = new Tag(rs.getString(2)); - ret.setId(tid); - ret.setSynonymId(rs.getInt(1)); - return ret; - }, + "SELECT tag_id, synonym_id, name, noindex, notop FROM tags WHERE tag_id=?", + new TagMapper(), tid); return list.isEmpty() ? null : list.get(0); @@ -67,25 +74,20 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { @Transactional @Override - public Tag getTag(final String tag, final boolean autoCreate) { - if (StringUtils.isBlank(tag)) + public Tag getTag(final String tagName, final boolean autoCreate) { + if (StringUtils.isBlank(tagName)) return null; List list = getJdbcTemplate().query( - "SELECT tag_id, synonym_id, name FROM tags WHERE name = ?", - (rs, rowNum) -> { - Tag ret1 = new Tag(rs.getString(3)); - ret1.setId(rs.getInt(1)); - ret1.setSynonymId(rs.getInt(2)); - return ret1; - }, - tag); + "SELECT tag_id, synonym_id, name, noindex, notop FROM tags WHERE name = ?", + new TagMapper(), + tagName); Tag ret = list.isEmpty() ? null : list.get(0); if (ret == null && autoCreate) { - ret = new Tag(tag); - ret.setId(createTag(tag)); + ret = new Tag(tagName); + ret.setId(createTag(tagName)); } return ret; @@ -98,15 +100,6 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { .toList(); } - @Transactional(readOnly = true) - @Override - public boolean getTagNoIndex(final int tagId) { - List list = getJdbcTemplate().queryForList( - "SELECT noindex FROM tags WHERE tag_id=?", Boolean.class, tagId); - - return !list.isEmpty() && list.get(0); - } - @Transactional @Override public int createTag(final String name) { @@ -162,9 +155,9 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { @Override public List getPopularTags() { return getJdbcTemplate().queryForList(""" - select name from tags where noindex=0 - order by stat_messages desc - """ + limit(20), String.class); + select name from tags where noindex=0 + order by stat_messages desc + """ + limit(20), String.class); } @Transactional(readOnly = true) diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java index 49736a60..2a1c89ae 100644 --- a/src/main/java/com/juick/www/controllers/Site.java +++ b/src/main/java/com/juick/www/controllers/Site.java @@ -33,7 +33,6 @@ import jakarta.servlet.http.HttpSession; import com.juick.service.*; import com.juick.util.MessageUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.text.StringEscapeUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; @@ -50,7 +49,6 @@ import javax.inject.Inject; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Optional; @@ -289,7 +287,7 @@ public class Site { String head = ""; head += "\n"; - if (paramTag != null && tagService.getTagNoIndex(paramTag.getId())) { + if (paramTag != null && tagService.getTag(paramTag.getId()).isNotIndexed()) { head += ""; } else if (before > 0 || paramShow != null) { head += ""; @@ -435,7 +433,7 @@ public class Site { } String head = StringUtils.EMPTY; - if (tagService.getTagNoIndex(paramTag.getId())) { + if (tagService.getTag(paramTag.getId()).isNotIndexed()) { head = ""; } else if (before > 0 || mids.size() < 5) { head = ""; -- cgit v1.2.3