Skip to content

Commit

Permalink
♻️ Repository 查询结果 rslts 使用 List 类型 #27
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed May 31, 2020
1 parent c9bf5d3 commit 90f3701
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions src/main/java/org/b3log/symphony/service/CommentQueryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
import org.b3log.latke.repository.*;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.service.annotation.Service;
import org.b3log.latke.util.*;
import org.b3log.latke.util.Locales;
import org.b3log.latke.util.Paginator;
import org.b3log.latke.util.Stopwatchs;
import org.b3log.latke.util.Times;
import org.b3log.symphony.model.*;
import org.b3log.symphony.repository.ArticleRepository;
import org.b3log.symphony.repository.CommentRepository;
Expand Down Expand Up @@ -153,10 +156,9 @@ public JSONObject getOfferedComment(final int commentViewMode, final String arti
.setFilter(CompositeFilterOperator.and(
new PropertyFilter(Comment.COMMENT_ON_ARTICLE_ID, FilterOperator.EQUAL, articleId),
new PropertyFilter(Comment.COMMENT_QNA_OFFERED, FilterOperator.EQUAL, Comment.COMMENT_QNA_OFFERED_C_YES),
new PropertyFilter(Comment.COMMENT_STATUS, FilterOperator.EQUAL, Comment.COMMENT_STATUS_C_VALID)
));
new PropertyFilter(Comment.COMMENT_STATUS, FilterOperator.EQUAL, Comment.COMMENT_STATUS_C_VALID)));
try {
final List<JSONObject> comments = CollectionUtils.jsonArrayToList(commentRepository.get(query).optJSONArray(Keys.RESULTS));
final List<JSONObject> comments = commentRepository.getList(query);
if (comments.isEmpty()) {
return null;
}
Expand All @@ -167,11 +169,9 @@ public JSONObject getOfferedComment(final int commentViewMode, final String arti
final int pageSize = Symphonys.ARTICLE_COMMENTS_CNT;
ret.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, getCommentPage(
articleId, ret.optString(Keys.OBJECT_ID), commentViewMode, pageSize));

return ret;
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Gets accepted comment failed", e);

return null;
}
} finally {
Expand Down Expand Up @@ -287,16 +287,11 @@ public List<JSONObject> getReplies(final String currentUserId, final int comment
setPage(1, Integer.MAX_VALUE).setPageCount(1).
setFilter(CompositeFilterOperator.and(
new PropertyFilter(Comment.COMMENT_ORIGINAL_COMMENT_ID, FilterOperator.EQUAL, commentId),
new PropertyFilter(Comment.COMMENT_STATUS, FilterOperator.EQUAL, Comment.COMMENT_STATUS_C_VALID)
));
new PropertyFilter(Comment.COMMENT_STATUS, FilterOperator.EQUAL, Comment.COMMENT_STATUS_C_VALID)));
try {
final List<JSONObject> comments = CollectionUtils.jsonArrayToList(
commentRepository.get(query).optJSONArray(Keys.RESULTS));

final List<JSONObject> comments = commentRepository.getList(query);
organizeComments(comments);

final int pageSize = Symphonys.ARTICLE_COMMENTS_CNT;

final List<JSONObject> ret = new ArrayList<>();
for (final JSONObject comment : comments) {
final JSONObject reply = new JSONObject();
Expand Down Expand Up @@ -358,16 +353,11 @@ public List<JSONObject> getNiceComments(final int commentViewMode,
setFilter(CompositeFilterOperator.and(
new PropertyFilter(Comment.COMMENT_ON_ARTICLE_ID, FilterOperator.EQUAL, articleId),
new PropertyFilter(Comment.COMMENT_SCORE, FilterOperator.GREATER_THAN, 0D),
new PropertyFilter(Comment.COMMENT_STATUS, FilterOperator.EQUAL, Comment.COMMENT_STATUS_C_VALID)
));
new PropertyFilter(Comment.COMMENT_STATUS, FilterOperator.EQUAL, Comment.COMMENT_STATUS_C_VALID)));
try {
final List<JSONObject> ret = CollectionUtils.jsonArrayToList(
commentRepository.get(query).optJSONArray(Keys.RESULTS));

final List<JSONObject> ret = commentRepository.getList(query);
organizeComments(ret);

final int pageSize = Symphonys.ARTICLE_COMMENTS_CNT;

for (final JSONObject comment : ret) {
comment.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, getCommentPage(
articleId, comment.optString(Keys.OBJECT_ID),
Expand All @@ -377,7 +367,6 @@ public List<JSONObject> getNiceComments(final int commentViewMode,
return ret;
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Get nice comments failed", e);

return Collections.emptyList();
}
} finally {
Expand Down Expand Up @@ -499,7 +488,7 @@ public List<JSONObject> getUserComments(final String userId, final int anonymous
new PropertyFilter(Comment.COMMENT_STATUS, FilterOperator.EQUAL, Comment.COMMENT_STATUS_C_VALID)));
try {
final JSONObject result = commentRepository.get(query);
final List<JSONObject> ret = CollectionUtils.jsonArrayToList(result.optJSONArray(Keys.RESULTS));
final List<JSONObject> ret = (List<JSONObject>) result.opt(Keys.RESULTS);
if (ret.isEmpty()) {
return ret;
}
Expand Down Expand Up @@ -631,8 +620,7 @@ public List<JSONObject> getArticleComments(final String articleId, final int cur
} finally {
Stopwatchs.end();
}
final List<JSONObject> ret = CollectionUtils.jsonArrayToList(result.optJSONArray(Keys.RESULTS));

final List<JSONObject> ret = (List<JSONObject>) result.opt(Keys.RESULTS);
organizeComments(ret);

Stopwatchs.start("Revision, paging, original");
Expand Down

0 comments on commit 90f3701

Please sign in to comment.