Commit 78f0ff30 authored by Liang Ding's avatar Liang Ding

#12633

parent 40cb1365
...@@ -319,11 +319,6 @@ public final class Option { ...@@ -319,11 +319,6 @@ public final class Option {
*/ */
public static final String ID_C_STATISTIC_BLOG_VIEW_COUNT = "statisticBlogViewCount"; public static final String ID_C_STATISTIC_BLOG_VIEW_COUNT = "statisticBlogViewCount";
/**
* Key of statistic blog comment(published article) count.
*/
public static final String ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT = "statisticPublishedBlogCommentCount";
/** /**
* Key of oauth GitHub. * Key of oauth GitHub.
*/ */
......
...@@ -113,8 +113,9 @@ public class BlogProcessor { ...@@ -113,8 +113,9 @@ public class BlogProcessor {
final JSONObject statistic = statisticQueryService.getStatistic(); final JSONObject statistic = statisticQueryService.getStatistic();
// TODO: 重构数据统计计数 #12633 jsonObject.put("articleCount", statistic.getLong(Option.ID_C_STATISTIC_PUBLISHED_ARTICLE_COUNT)); // TODO: 重构数据统计计数 #12633
jsonObject.put("commentCount", statistic.getLong(Option.ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT)); // jsonObject.put("articleCount", statistic.getLong(Option.ID_C_STATISTIC_PUBLISHED_ARTICLE_COUNT));
// jsonObject.put("commentCount", statistic.getLong(Option.ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT));
jsonObject.put("tagCount", tagQueryService.getTagCount()); jsonObject.put("tagCount", tagQueryService.getTagCount());
jsonObject.put("servePath", Latkes.getServePath()); jsonObject.put("servePath", Latkes.getServePath());
jsonObject.put("staticServePath", Latkes.getStaticServePath()); jsonObject.put("staticServePath", Latkes.getStaticServePath());
......
...@@ -52,7 +52,7 @@ import java.util.Date; ...@@ -52,7 +52,7 @@ import java.util.Date;
* Receiving comments from B3log community. Visits <a href="https://hacpai.com/b3log">B3log 构思</a> for more details. * Receiving comments from B3log community. Visits <a href="https://hacpai.com/b3log">B3log 构思</a> for more details.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.1.19, Nov 6, 2018 * @version 1.1.1.20, Jan 28, 2019
* @since 0.5.5 * @since 0.5.5
*/ */
@RequestProcessor @RequestProcessor
...@@ -224,26 +224,20 @@ public class B3CommentReceiver { ...@@ -224,26 +224,20 @@ public class B3CommentReceiver {
} }
ret.put(Comment.COMMENT_THUMBNAIL_URL, comment.getString(Comment.COMMENT_THUMBNAIL_URL)); ret.put(Comment.COMMENT_THUMBNAIL_URL, comment.getString(Comment.COMMENT_THUMBNAIL_URL));
// Sets comment on article....
comment.put(Comment.COMMENT_ON_ID, articleId); comment.put(Comment.COMMENT_ON_ID, articleId);
comment.put(Comment.COMMENT_ON_TYPE, Article.ARTICLE); comment.put(Comment.COMMENT_ON_TYPE, Article.ARTICLE);
final String commentSharpURL = Comment.getCommentSharpURLForArticle(article, commentId); final String commentSharpURL = Comment.getCommentSharpURLForArticle(article, commentId);
comment.put(Comment.COMMENT_SHARP_URL, commentSharpURL); comment.put(Comment.COMMENT_SHARP_URL, commentSharpURL);
commentRepository.add(comment); commentRepository.add(comment);
// Step 2: Update article comment count
articleMgmtService.incArticleCommentCount(articleId); articleMgmtService.incArticleCommentCount(articleId);
// Step 3: Update blog statistic comment count
statisticMgmtService.incPublishedBlogCommentCount();
// Step 4: Send an email to admin
try { try {
commentMgmtService.sendNotificationMail(article, comment, originalComment, preference); commentMgmtService.sendNotificationMail(article, comment, originalComment, preference);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.WARN, "Send mail failed", e); LOGGER.log(Level.WARN, "Send mail failed", e);
} }
// Step 5: Fire add comment event
final JSONObject eventData = new JSONObject();
final JSONObject eventData = new JSONObject();
eventData.put(Comment.COMMENT, comment); eventData.put(Comment.COMMENT, comment);
eventData.put(Article.ARTICLE, article); eventData.put(Article.ARTICLE, article);
eventManager.fireEventSynchronously(new Event<>(EventTypes.ADD_COMMENT_TO_ARTICLE_FROM_SYMPHONY, eventData)); eventManager.fireEventSynchronously(new Event<>(EventTypes.ADD_COMMENT_TO_ARTICLE_FROM_SYMPHONY, eventData));
......
...@@ -202,11 +202,6 @@ public class ArticleMgmtService { ...@@ -202,11 +202,6 @@ public class ArticleMgmtService {
decArchiveDatePublishedRefCount(articleId); decArchiveDatePublishedRefCount(articleId);
articleRepository.update(articleId, article); articleRepository.update(articleId, article);
final int blogCmtCnt = statisticQueryService.getPublishedBlogCommentCount();
final int articleCmtCnt = article.getInt(ARTICLE_COMMENT_COUNT);
statisticMgmtService.setPublishedBlogCommentCount(blogCmtCnt - articleCmtCnt);
final JSONObject author = userRepository.get(article.optString(Article.ARTICLE_AUTHOR_ID)); final JSONObject author = userRepository.get(article.optString(Article.ARTICLE_AUTHOR_ID));
author.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, author.optInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT) - 1); author.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, author.optInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT) - 1);
userRepository.update(author.optString(Keys.OBJECT_ID), author); userRepository.update(author.optString(Keys.OBJECT_ID), author);
...@@ -339,11 +334,6 @@ public class ArticleMgmtService { ...@@ -339,11 +334,6 @@ public class ArticleMgmtService {
// Set statistic // Set statistic
if (publishNewArticle) { if (publishNewArticle) {
// This article is updated from unpublished to published
final int blogCmtCnt = statisticQueryService.getPublishedBlogCommentCount();
final int articleCmtCnt = article.getInt(ARTICLE_COMMENT_COUNT);
statisticMgmtService.setPublishedBlogCommentCount(blogCmtCnt + articleCmtCnt);
final JSONObject author = userRepository.get(article.optString(Article.ARTICLE_AUTHOR_ID)); final JSONObject author = userRepository.get(article.optString(Article.ARTICLE_AUTHOR_ID));
author.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, author.optInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT) + 1); author.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, author.optInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT) + 1);
userRepository.update(author.optString(Keys.OBJECT_ID), author); userRepository.update(author.optString(Keys.OBJECT_ID), author);
...@@ -536,7 +526,6 @@ public class ArticleMgmtService { ...@@ -536,7 +526,6 @@ public class ArticleMgmtService {
decTagRefCount(articleId); decTagRefCount(articleId);
unArchiveDate(articleId); unArchiveDate(articleId);
removeTagArticleRelations(articleId); removeTagArticleRelations(articleId);
removeArticleComments(articleId);
final JSONObject article = articleRepository.get(articleId); final JSONObject article = articleRepository.get(articleId);
...@@ -955,26 +944,6 @@ public class ArticleMgmtService { ...@@ -955,26 +944,6 @@ public class ArticleMgmtService {
return ret; return ret;
} }
/**
* Removes article comments by the specified article id.
* <p>
* Removes related comments, sets article/blog comment statistic count.
* </p>
*
* @param articleId the specified article id
* @throws Exception exception
*/
private void removeArticleComments(final String articleId) throws Exception {
final int removedCnt = commentRepository.removeComments(articleId);
final JSONObject article = articleRepository.get(articleId);
if (article.optBoolean(Article.ARTICLE_IS_PUBLISHED)) {
int publishedBlogCommentCount = statisticQueryService.getPublishedBlogCommentCount();
publishedBlogCommentCount -= removedCnt;
statisticMgmtService.setPublishedBlogCommentCount(publishedBlogCommentCount);
}
}
/** /**
* Archive the create date with the specified article. * Archive the create date with the specified article.
* *
......
...@@ -445,13 +445,10 @@ public class CommentMgmtService { ...@@ -445,13 +445,10 @@ public class CommentMgmtService {
} }
setCommentThumbnailURL(comment); setCommentThumbnailURL(comment);
ret.put(Comment.COMMENT_THUMBNAIL_URL, comment.getString(Comment.COMMENT_THUMBNAIL_URL)); ret.put(Comment.COMMENT_THUMBNAIL_URL, comment.getString(Comment.COMMENT_THUMBNAIL_URL));
// Sets comment on page....
comment.put(Comment.COMMENT_ON_ID, pageId); comment.put(Comment.COMMENT_ON_ID, pageId);
comment.put(Comment.COMMENT_ON_TYPE, Page.PAGE); comment.put(Comment.COMMENT_ON_TYPE, Page.PAGE);
final String commentId = Ids.genTimeMillisId(); final String commentId = Ids.genTimeMillisId();
ret.put(Keys.OBJECT_ID, commentId); ret.put(Keys.OBJECT_ID, commentId);
// Save comment sharp URL
final String commentSharpURL = Comment.getCommentSharpURLForPage(page, commentId); final String commentSharpURL = Comment.getCommentSharpURLForPage(page, commentId);
ret.put(Comment.COMMENT_NAME, commentName); ret.put(Comment.COMMENT_NAME, commentName);
ret.put(Comment.COMMENT_CONTENT, commentContent); ret.put(Comment.COMMENT_CONTENT, commentContent);
...@@ -461,19 +458,14 @@ public class CommentMgmtService { ...@@ -461,19 +458,14 @@ public class CommentMgmtService {
comment.put(Comment.COMMENT_SHARP_URL, commentSharpURL); comment.put(Comment.COMMENT_SHARP_URL, commentSharpURL);
comment.put(Keys.OBJECT_ID, commentId); comment.put(Keys.OBJECT_ID, commentId);
commentRepository.add(comment); commentRepository.add(comment);
// Step 2: Update page comment count
incPageCommentCount(pageId); incPageCommentCount(pageId);
// Step 3: Update blog statistic comment count
statisticMgmtService.incPublishedBlogCommentCount();
// Step 4: Send an email to admin
try { try {
sendNotificationMail(page, comment, originalComment, preference); sendNotificationMail(page, comment, originalComment, preference);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.WARN, "Send mail failed", e); LOGGER.log(Level.WARN, "Send mail failed", e);
} }
// Step 5: Fire add comment event
final JSONObject eventData = new JSONObject();
final JSONObject eventData = new JSONObject();
eventData.put(Comment.COMMENT, comment); eventData.put(Comment.COMMENT, comment);
eventData.put(Page.PAGE, page); eventData.put(Page.PAGE, page);
eventManager.fireEventSynchronously(new Event<>(EventTypes.ADD_COMMENT_TO_PAGE, eventData)); eventManager.fireEventSynchronously(new Event<>(EventTypes.ADD_COMMENT_TO_PAGE, eventData));
...@@ -586,7 +578,6 @@ public class CommentMgmtService { ...@@ -586,7 +578,6 @@ public class CommentMgmtService {
} }
setCommentThumbnailURL(comment); setCommentThumbnailURL(comment);
ret.put(Comment.COMMENT_THUMBNAIL_URL, comment.getString(Comment.COMMENT_THUMBNAIL_URL)); ret.put(Comment.COMMENT_THUMBNAIL_URL, comment.getString(Comment.COMMENT_THUMBNAIL_URL));
// Sets comment on article....
comment.put(Comment.COMMENT_ON_ID, articleId); comment.put(Comment.COMMENT_ON_ID, articleId);
comment.put(Comment.COMMENT_ON_TYPE, Article.ARTICLE); comment.put(Comment.COMMENT_ON_TYPE, Article.ARTICLE);
final String commentId = Ids.genTimeMillisId(); final String commentId = Ids.genTimeMillisId();
...@@ -598,19 +589,15 @@ public class CommentMgmtService { ...@@ -598,19 +589,15 @@ public class CommentMgmtService {
ret.put(Comment.COMMENT_SHARP_URL, commentSharpURL); ret.put(Comment.COMMENT_SHARP_URL, commentSharpURL);
commentRepository.add(comment); commentRepository.add(comment);
// Step 2: Update article comment count
articleMgmtService.incArticleCommentCount(articleId); articleMgmtService.incArticleCommentCount(articleId);
// Step 3: Update blog statistic comment count
statisticMgmtService.incPublishedBlogCommentCount();
// Step 4: Send an email to admin
try { try {
sendNotificationMail(article, comment, originalComment, preference); sendNotificationMail(article, comment, originalComment, preference);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.WARN, "Send mail failed", e); LOGGER.log(Level.WARN, "Send mail failed", e);
} }
// Step 5: Fire add comment event
final JSONObject eventData = new JSONObject();
final JSONObject eventData = new JSONObject();
eventData.put(Comment.COMMENT, comment); eventData.put(Comment.COMMENT, comment);
eventData.put(Article.ARTICLE, article); eventData.put(Article.ARTICLE, article);
eventManager.fireEventSynchronously(new Event<>(EventTypes.ADD_COMMENT_TO_ARTICLE, eventData)); eventManager.fireEventSynchronously(new Event<>(EventTypes.ADD_COMMENT_TO_ARTICLE, eventData));
...@@ -639,13 +626,8 @@ public class CommentMgmtService { ...@@ -639,13 +626,8 @@ public class CommentMgmtService {
try { try {
final JSONObject comment = commentRepository.get(commentId); final JSONObject comment = commentRepository.get(commentId);
final String pageId = comment.getString(Comment.COMMENT_ON_ID); final String pageId = comment.getString(Comment.COMMENT_ON_ID);
// Step 1: Remove comment
commentRepository.remove(commentId); commentRepository.remove(commentId);
// Step 2: Update page comment count
decPageCommentCount(pageId); decPageCommentCount(pageId);
// Step 3: Update blog statistic comment count
statisticMgmtService.decPublishedBlogCommentCount();
transaction.commit(); transaction.commit();
} catch (final Exception e) { } catch (final Exception e) {
...@@ -671,13 +653,8 @@ public class CommentMgmtService { ...@@ -671,13 +653,8 @@ public class CommentMgmtService {
try { try {
final JSONObject comment = commentRepository.get(commentId); final JSONObject comment = commentRepository.get(commentId);
final String articleId = comment.getString(Comment.COMMENT_ON_ID); final String articleId = comment.getString(Comment.COMMENT_ON_ID);
// Step 1: Remove comment
commentRepository.remove(commentId); commentRepository.remove(commentId);
// Step 2: Update article comment count
decArticleCommentCount(articleId); decArticleCommentCount(articleId);
// Step 3: Update blog statistic comment count
statisticMgmtService.decPublishedBlogCommentCount();
transaction.commit(); transaction.commit();
} catch (final Exception e) { } catch (final Exception e) {
......
...@@ -302,23 +302,14 @@ public class InitService { ...@@ -302,23 +302,14 @@ public class InitService {
try { try {
article.put(Keys.OBJECT_ID, ret); article.put(Keys.OBJECT_ID, ret);
// Step 1: Add tags
final String tagsString = article.optString(Article.ARTICLE_TAGS_REF); final String tagsString = article.optString(Article.ARTICLE_TAGS_REF);
final String[] tagTitles = tagsString.split(","); final String[] tagTitles = tagsString.split(",");
final JSONArray tags = tag(tagTitles, article); final JSONArray tags = tag(tagTitles, article);
// Step 2: Add tag-article relations
addTagArticleRelation(tags, article); addTagArticleRelation(tags, article);
// Step 3: Inc blog article and comment count statictis
statisticMgmtService.incPublishedBlogCommentCount();
// Step 4: Add archive date-article relations
archiveDate(article); archiveDate(article);
// Step 5: Add article
articleRepository.add(article); articleRepository.add(article);
// Step 6: Update admin user for article statistic
final JSONObject admin = userRepository.getAdmin();
final JSONObject admin = userRepository.getAdmin();
admin.put(UserExt.USER_ARTICLE_COUNT, 1); admin.put(UserExt.USER_ARTICLE_COUNT, 1);
admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 1); admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 1);
userRepository.update(admin.optString(Keys.OBJECT_ID), admin); userRepository.update(admin.optString(Keys.OBJECT_ID), admin);
...@@ -484,12 +475,6 @@ public class InitService { ...@@ -484,12 +475,6 @@ public class InitService {
statisticBlogViewCountOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_STATISTIC); statisticBlogViewCountOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_STATISTIC);
optionRepository.add(statisticBlogViewCountOpt); optionRepository.add(statisticBlogViewCountOpt);
final JSONObject statisticPublishedBlogCommentCountOpt = new JSONObject();
statisticPublishedBlogCommentCountOpt.put(Keys.OBJECT_ID, Option.ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT);
statisticPublishedBlogCommentCountOpt.put(Option.OPTION_VALUE, "0");
statisticPublishedBlogCommentCountOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_STATISTIC);
optionRepository.add(statisticPublishedBlogCommentCountOpt);
LOGGER.debug("Initialized statistic"); LOGGER.debug("Initialized statistic");
} }
......
...@@ -253,51 +253,6 @@ public class StatisticMgmtService { ...@@ -253,51 +253,6 @@ public class StatisticMgmtService {
LOGGER.log(Level.TRACE, "Inced blog view count[statistic={0}]", statistic); LOGGER.log(Level.TRACE, "Inced blog view count[statistic={0}]", statistic);
} }
/**
* Blog statistic comment(published article) count +1.
*
* @throws RepositoryException repository exception
*/
public void incPublishedBlogCommentCount() throws RepositoryException {
final JSONObject statistic = optionRepository.get(Option.ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT);
if (null == statistic) {
throw new RepositoryException("Not found statistic");
}
statistic.put(Option.OPTION_VALUE, statistic.optInt(Option.OPTION_VALUE) + 1);
updateStatistic(Option.ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT, statistic);
}
/**
* Blog statistic comment(published article) count -1.
*
* @throws RepositoryException repository exception
*/
public void decPublishedBlogCommentCount() throws RepositoryException {
final JSONObject statistic = optionRepository.get(Option.ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT);
if (null == statistic) {
throw new RepositoryException("Not found statistic");
}
statistic.put(Option.OPTION_VALUE, statistic.optInt(Option.OPTION_VALUE) - 1);
updateStatistic(Option.ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT, statistic);
}
/**
* Sets blog comment(published article) count with the specified count.
*
* @param count the specified count
* @throws RepositoryException repository exception
*/
public void setPublishedBlogCommentCount(final int count) throws RepositoryException {
final JSONObject statistic = optionRepository.get(Option.ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT);
if (null == statistic) {
throw new RepositoryException("Not found statistic");
}
statistic.put(Option.OPTION_VALUE, count);
updateStatistic(Option.ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT, statistic);
}
/** /**
* Refreshes online visitor count for the specified request. * Refreshes online visitor count for the specified request.
* *
......
...@@ -20,7 +20,6 @@ package org.b3log.solo.service; ...@@ -20,7 +20,6 @@ package org.b3log.solo.service;
import org.b3log.latke.ioc.Inject; import org.b3log.latke.ioc.Inject;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.service.ServiceException;
import org.b3log.latke.service.annotation.Service; import org.b3log.latke.service.annotation.Service;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -55,21 +54,6 @@ public class StatisticQueryService { ...@@ -55,21 +54,6 @@ public class StatisticQueryService {
return StatisticMgmtService.ONLINE_VISITORS.size(); return StatisticMgmtService.ONLINE_VISITORS.size();
} }
/**
* Get blog comment(published article) count.
*
* @return blog comment count
* @throws ServiceException service exception
*/
public int getPublishedBlogCommentCount() throws ServiceException {
final JSONObject opt = optionQueryService.getOptionById(Option.ID_C_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT);
if (null == opt) {
throw new ServiceException("Not found statistic");
}
return opt.optInt(Option.OPTION_VALUE);
}
/** /**
* Gets the statistic. * Gets the statistic.
* *
......
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