aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-02-03 02:13:17 +0300
committerGravatar Vitaly Takmazov2023-02-03 03:39:43 +0300
commit22aaf28c779725962a3ebec3e689bef35fe05085 (patch)
tree71e05ad64efc73dff7ba3d6688a567493bc88c09 /src/main
parentd71ce6095b87958d2df4da27b1344ad0e5b77a44 (diff)
GetTagNoIndex -> tag.isNotIndexed
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/juick/model/Tag.java16
-rw-r--r--src/main/java/com/juick/service/TagService.java2
-rw-r--r--src/main/java/com/juick/service/TagServiceImpl.java55
-rw-r--r--src/main/java/com/juick/www/controllers/Site.java6
4 files changed, 42 insertions, 37 deletions
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<Tag>, 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<Tag>, 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<Tag> getTags(Stream<String> tags, boolean autoCreate);
- boolean getTagNoIndex(int tagId);
-
int createTag(String name);
List<TagStats> 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<Tag> {
+ @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<Tag> 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<Tag> 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<Boolean> 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<String> 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 = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + user.getName()
+ "\" href=\"//rss.juick.com/" + user.getName() + "/blog\"/>";
head += "<meta name=\"Description\" content=\"" + title + "\" />\n";
- if (paramTag != null && tagService.getTagNoIndex(paramTag.getId())) {
+ if (paramTag != null && tagService.getTag(paramTag.getId()).isNotIndexed()) {
head += "<meta name=\"robots\" content=\"noindex,nofollow\"/>";
} else if (before > 0 || paramShow != null) {
head += "<meta name=\"robots\" content=\"noindex\"/>";
@@ -435,7 +433,7 @@ public class Site {
}
String head = StringUtils.EMPTY;
- if (tagService.getTagNoIndex(paramTag.getId())) {
+ if (tagService.getTag(paramTag.getId()).isNotIndexed()) {
head = "<meta name=\"robots\" content=\"noindex,nofollow\"/>";
} else if (before > 0 || mids.size() < 5) {
head = "<meta name=\"robots\" content=\"noindex\"/>";