Skip to content

Commit

Permalink
b3log#525 随机帖子性能优化
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jan 9, 2018
1 parent 69493e3 commit 2520e49
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/main/java/org/b3log/symphony/repository/ArticleRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* Article repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.1.2, Jan 6, 2018
* @version 1.1.1.3, Jan 9, 2018
* @since 0.2.0
*/
@Repository
Expand Down Expand Up @@ -99,7 +99,6 @@ public List<JSONObject> getRandomly(final int fetchSize) throws RepositoryExcept
addProjection(Article.ARTICLE_PERMALINK, String.class).
addProjection(Article.ARTICLE_AUTHOR_ID, String.class).
setCurrentPageNum(1).setPageSize(fetchSize).setPageCount(1);

final JSONObject result1 = get(query);
final JSONArray array1 = result1.optJSONArray(Keys.RESULTS);

Expand All @@ -108,18 +107,16 @@ public List<JSONObject> getRandomly(final int fetchSize) throws RepositoryExcept

final int reminingSize = fetchSize - array1.length();
if (0 != reminingSize) { // Query for remains
query = new Query();
query.setFilter(
query = new Query().setFilter(
CompositeFilterOperator.and(new PropertyFilter(Article.ARTICLE_RANDOM_DOUBLE, FilterOperator.GREATER_THAN_OR_EQUAL, 0D),
new PropertyFilter(Article.ARTICLE_RANDOM_DOUBLE, FilterOperator.LESS_THAN_OR_EQUAL, mid),
new PropertyFilter(Article.ARTICLE_STATUS, FilterOperator.EQUAL, Article.ARTICLE_STATUS_C_VALID)));
query.setCurrentPageNum(1);
query.setPageSize(reminingSize);
query.setPageCount(1);

new PropertyFilter(Article.ARTICLE_STATUS, FilterOperator.EQUAL, Article.ARTICLE_STATUS_C_VALID))).
addProjection(Article.ARTICLE_TITLE, String.class).
addProjection(Article.ARTICLE_PERMALINK, String.class).
addProjection(Article.ARTICLE_AUTHOR_ID, String.class).
setCurrentPageNum(1).setPageSize(reminingSize).setPageCount(1);
final JSONObject result2 = get(query);
final JSONArray array2 = result2.optJSONArray(Keys.RESULTS);

final List<JSONObject> list2 = CollectionUtils.jsonArrayToList(array2);

ret.addAll(list2);
Expand Down

0 comments on commit 2520e49

Please sign in to comment.