Skip to content

Commit

Permalink
🔥 #45
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jan 16, 2020
1 parent 6916dad commit 1953030
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 129 deletions.
5 changes: 0 additions & 5 deletions src/main/java/org/b3log/solo/model/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/org/b3log/solo/repository/CommentRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,6 @@ public void update(final String id, final JSONObject comment, final String... pr
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.
Expand Down
51 changes: 0 additions & 51 deletions src/main/java/org/b3log/solo/service/DataModelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
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.*;
Expand Down Expand Up @@ -454,47 +452,6 @@ public void fillRecentArticles(final Map<String, Object> dataModel, final JSONOb
}
}

/**
* 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
*
Expand Down Expand Up @@ -742,10 +699,6 @@ private void fillSide(final RequestContext context, final Map<String, Object> da
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);
Expand Down Expand Up @@ -781,10 +734,6 @@ public void fillUserTemplate(final RequestContext context, final Template templa
fillCategories(dataModel);
}

if (Templates.hasExpression(template, "<#list recentComments as comment>")) {
fillRecentComments(dataModel, preference);
}

if (Templates.hasExpression(template, "<#include \"side.ftl\"/>")) {
fillSide(context, dataModel, preference);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void getArticleComments() throws Exception {
*/
@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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void previousAndNext() throws Exception {
*
* @throws Exception exception
*/
@Test(dependsOnMethods = {"add", "previousAndNext", "getMostCommentArticles", "getMostViewCountArticles"})
@Test(dependsOnMethods = {"add", "previousAndNext"})
public void getRandomly() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();

Expand All @@ -162,27 +162,26 @@ public void getRandomly() throws Exception {
*
* @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");
}

/**
* Is Published.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = {"add", "getMostViewCountArticles"})
@Test(dependsOnMethods = {"add"})
public void isPublished() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();

Expand All @@ -192,9 +191,9 @@ public void isPublished() throws Exception {
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"));
}
Expand Down
43 changes: 0 additions & 43 deletions src/test/resources/log4j.properties

This file was deleted.

0 comments on commit 1953030

Please sign in to comment.