Commit 1953030e authored by Liang Ding's avatar Liang Ding

🔥 #45

parent 6916dad9
......@@ -102,11 +102,6 @@ public final class Common {
*/
public static final String RECENT_ARTICLES = "recentArticles";
/**
* Recent comments.
*/
public static final String RECENT_COMMENTS = "recentComments";
/**
* Previous article permalink.
*/
......
......@@ -97,24 +97,6 @@ public class CommentRepository extends AbstractRepository {
commentCache.putComment(comment);
}
/**
* Gets post comments recently with the specified fetch.
*
* @param fetchSize the specified fetch size
* @return a list of comments recently, returns an empty list if not found
* @throws RepositoryException repository exception
*/
public List<JSONObject> getRecentComments(final int fetchSize) throws RepositoryException {
final Query query = new Query().
addSort(Keys.OBJECT_ID, SortDirection.DESCENDING).
setPage(1, fetchSize).setPageCount(1);
final List<JSONObject> ret = getList(query);
// Removes unpublished article related comments
removeForUnpublishedArticles(ret);
return ret;
}
/**
* Gets comments with the specified on id, current page number and
* page size.
......
......@@ -47,8 +47,6 @@ import org.b3log.solo.util.Markdowns;
import org.b3log.solo.util.Skins;
import org.b3log.solo.util.Solos;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import java.io.StringWriter;
import java.util.*;
......@@ -454,47 +452,6 @@ public class DataModelService {
}
}
/**
* Fills post comments recently.
*
* @param dataModel data model
* @param preference the specified preference
* @throws ServiceException service exception
*/
public void fillRecentComments(final Map<String, Object> dataModel, final JSONObject preference) throws ServiceException {
if (!preference.optBoolean(Option.ID_C_COMMENTABLE)) {
dataModel.put(Common.RECENT_COMMENTS, Collections.emptyList());
return;
}
Stopwatchs.start("Fill Recent Comments");
try {
LOGGER.debug("Filling recent comments....");
final int recentCommentDisplayCnt = preference.getInt(Option.ID_C_RECENT_COMMENT_DISPLAY_CNT);
final List<JSONObject> recentComments = commentRepository.getRecentComments(recentCommentDisplayCnt);
for (final JSONObject comment : recentComments) {
String commentContent = comment.optString(Comment.COMMENT_CONTENT);
commentContent = Markdowns.toHTML(commentContent);
commentContent = Jsoup.clean(commentContent, Whitelist.relaxed());
comment.put(Comment.COMMENT_CONTENT, commentContent);
comment.put(Comment.COMMENT_NAME, comment.getString(Comment.COMMENT_NAME));
comment.put(Comment.COMMENT_URL, comment.getString(Comment.COMMENT_URL));
comment.put(Common.IS_REPLY, false);
comment.put(Comment.COMMENT_T_DATE, new Date(comment.optLong(Comment.COMMENT_CREATED)));
comment.put("commentDate2", new Date(comment.optLong(Comment.COMMENT_CREATED)));
}
dataModel.put(Common.RECENT_COMMENTS, recentComments);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Fills recent comments failed", e);
throw new ServiceException(e);
} finally {
Stopwatchs.end();
}
}
/**
* Fills favicon URL. 可配置 favicon 图标路径 https://github.com/b3log/solo/issues/12706
*
......@@ -742,10 +699,6 @@ public class DataModelService {
if (Templates.hasExpression(template, "<#list links as link>")) {
fillLinks(dataModel);
}
if (Templates.hasExpression(template, "<#list recentComments as comment>")) {
fillRecentComments(dataModel, preference);
}
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, "Fills side failed", e);
throw new ServiceException(e);
......@@ -781,10 +734,6 @@ public class DataModelService {
fillCategories(dataModel);
}
if (Templates.hasExpression(template, "<#list recentComments as comment>")) {
fillRecentComments(dataModel, preference);
}
if (Templates.hasExpression(template, "<#include \"side.ftl\"/>")) {
fillSide(context, dataModel, preference);
}
......
......@@ -19,6 +19,7 @@ package org.b3log.solo.processor.console;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.repository.Query;
import org.b3log.solo.AbstractTestCase;
import org.b3log.solo.MockRequest;
import org.b3log.solo.MockResponse;
......@@ -95,7 +96,7 @@ public class CommentConsoleTestCase extends AbstractTestCase {
*/
@Test(dependsOnMethods = "init")
public void removeArticleComment() throws Exception {
final List<JSONObject> recentComments = getCommentRepository().getRecentComments(1);
final List<JSONObject> recentComments = getCommentRepository().getList(new Query());
final JSONObject comment = recentComments.get(0);
final String commentId = comment.optString(Keys.OBJECT_ID);
......
......@@ -149,7 +149,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
*
* @throws Exception exception
*/
@Test(dependsOnMethods = {"add", "previousAndNext", "getMostCommentArticles", "getMostViewCountArticles"})
@Test(dependsOnMethods = {"add", "previousAndNext"})
public void getRandomly() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
......@@ -162,19 +162,18 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
*
* @throws Exception exception
*/
@Test(dependsOnMethods = {"add", "previousAndNext", "getMostCommentArticles", "getMostViewCountArticles"})
@Test(dependsOnMethods = {"add", "previousAndNext"})
public void getRecentArticles() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
Assert.assertEquals(articleRepository.count(), 4);
Assert.assertEquals(articleRepository.count(), 2);
List<JSONObject> recentArticles = articleRepository.getRecentArticles(3);
Assert.assertNotNull(recentArticles);
Assert.assertEquals(recentArticles.size(), 3);
Assert.assertEquals(recentArticles.size(), 2);
Assert.assertEquals(recentArticles.get(0).getString(Article.ARTICLE_TITLE), "article title3");
Assert.assertEquals(recentArticles.get(1).getString(Article.ARTICLE_TITLE), "article title2");
Assert.assertEquals(recentArticles.get(2).getString(Article.ARTICLE_TITLE), "article title1");
Assert.assertEquals(recentArticles.get(0).getString(Article.ARTICLE_TITLE), "article title2");
Assert.assertEquals(recentArticles.get(1).getString(Article.ARTICLE_TITLE), "article title1");
}
/**
......@@ -182,7 +181,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
*
* @throws Exception exception
*/
@Test(dependsOnMethods = {"add", "getMostViewCountArticles"})
@Test(dependsOnMethods = {"add"})
public void isPublished() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
......@@ -192,9 +191,9 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
final JSONObject article = all.getJSONObject(0);
Assert.assertTrue(articleRepository.isPublished(article.getString(Keys.OBJECT_ID)));
final JSONObject notPublished = articleRepository.getByPermalink("article permalink4");
Assert.assertNotNull(notPublished);
Assert.assertEquals(Article.ARTICLE_STATUS_C_DRAFT, notPublished.optInt(Article.ARTICLE_STATUS));
final JSONObject published = articleRepository.getByPermalink("article permalink1");
Assert.assertNotNull(published);
Assert.assertEquals(Article.ARTICLE_STATUS_C_PUBLISHED, published.optInt(Article.ARTICLE_STATUS));
Assert.assertFalse(articleRepository.isPublished("not found"));
}
......
#
# Solo - A small and beautiful blogging system written in Java.
# Copyright (c) 2010-present, b3log.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
# Description: Solo logging configurations for test.
# Version: 1.0.0.0, Mar 3, 2019
# Author: <a href="http://88250.b3log.org">Liang Ding</a>
#
log4j.rootLogger=INFO,stdout
log4j.logger.org.b3log.solo=INFO
log4j.logger.org.b3log.latke=WARN
log4j.logger.org.b3log.latke.util.freemarker.Templates=ERROR
log4j.logger.org.b3log.latke.repository.jdbc.util=WARN
log4j.logger.io.netty=WARN
log4j.logger.freemarker=WARN
log4j.logger.com.zaxxer=WARN
# Print only messages of level ERROR or above in the package noModule.
log4j.logger.noModule=ERROR
# Console appender
log4j.appender.stdout.Encoding=UTF-8
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%-5p]-[%d{yyyy-MM-dd HH:mm:ss}]-[%c:%L]: %m%n
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment