Commit a2766c9e authored by Liang Ding's avatar Liang Ding

🎨 数据不一致补偿清理

parent 9d26015d
...@@ -375,9 +375,7 @@ public class CommentMgmtService { ...@@ -375,9 +375,7 @@ public class CommentMgmtService {
final JSONObject article = articleRepository.get(articleId); final JSONObject article = articleRepository.get(articleId);
final JSONObject newArticle = new JSONObject(article, JSONObject.getNames(article)); final JSONObject newArticle = new JSONObject(article, JSONObject.getNames(article));
final int commentCnt = article.getInt(Article.ARTICLE_COMMENT_COUNT); final int commentCnt = article.getInt(Article.ARTICLE_COMMENT_COUNT);
newArticle.put(Article.ARTICLE_COMMENT_COUNT, commentCnt - 1); newArticle.put(Article.ARTICLE_COMMENT_COUNT, commentCnt - 1);
articleRepository.update(articleId, newArticle); articleRepository.update(articleId, newArticle);
} }
......
...@@ -19,7 +19,6 @@ package org.b3log.solo.service; ...@@ -19,7 +19,6 @@ package org.b3log.solo.service;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.ioc.BeanManager;
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;
...@@ -28,6 +27,7 @@ import org.b3log.latke.model.Role; ...@@ -28,6 +27,7 @@ import org.b3log.latke.model.Role;
import org.b3log.latke.model.User; import org.b3log.latke.model.User;
import org.b3log.latke.repository.Query; import org.b3log.latke.repository.Query;
import org.b3log.latke.repository.SortDirection; import org.b3log.latke.repository.SortDirection;
import org.b3log.latke.repository.Transaction;
import org.b3log.latke.service.ServiceException; import org.b3log.latke.service.ServiceException;
import org.b3log.latke.service.annotation.Service; import org.b3log.latke.service.annotation.Service;
import org.b3log.latke.util.Paginator; import org.b3log.latke.util.Paginator;
...@@ -172,10 +172,11 @@ public class CommentQueryService { ...@@ -172,10 +172,11 @@ public class CommentQueryService {
final JSONObject article = articleRepository.get(onId); final JSONObject article = articleRepository.get(onId);
if (null == article) { if (null == article) {
// 某种情况下导致的数据不一致:文章已经被删除了,但是评论还在 // 某种情况下导致的数据不一致:文章已经被删除了,但是评论还在
// 为了保持数据一致性,需要删除该条评论 // 为了保持数据一致性,需要删除该条评论 https://hacpai.com/article/1556060195022
// https://hacpai.com/article/1556060195022 final Transaction transaction = commentRepository.beginTransaction();
final CommentMgmtService commentMgmtService = BeanManager.getInstance().getReference(CommentMgmtService.class); final String commentId = comment.optString(Keys.OBJECT_ID);
commentMgmtService.removeArticleComment(onId); commentRepository.remove(commentId);
transaction.commit();
continue; continue;
} }
......
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