From 07d0694cf654cf68d361ceb2ba729a6c08e2a0d5 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 27 Jun 2014 17:33:26 +0200 Subject: [PATCH] Add pagination to ruby rules search query --- .../org/sonar/server/rule/RubyRuleService.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java b/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java index ea792ca1eee..5ea09af178c 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java @@ -32,6 +32,7 @@ import org.sonar.server.rule.index.RuleDoc; import org.sonar.server.rule.index.RuleNormalizer; import org.sonar.server.rule.index.RuleQuery; import org.sonar.server.search.QueryOptions; +import org.sonar.server.search.Result; import org.sonar.server.user.UserSession; import org.sonar.server.util.RubyUtils; @@ -59,7 +60,7 @@ public class RubyRuleService implements ServerComponent, Startable { } /** - * Used in issues_controller.rb and in manual_rules_controller.rb + * Used in issues_controller.rb and in manual_rules_controller.rb and in SQALE */ @CheckForNull public Rule findByKey(String ruleKey) { @@ -82,9 +83,14 @@ public class RubyRuleService implements ServerComponent, Startable { query.setHasDebtCharacteristic(RubyUtils.toBoolean(params.get("hasDebtCharacteristic"))); query.setSortField(RuleNormalizer.RuleField.NAME); - QueryOptions options = new QueryOptions().setScroll(true); - List rules = newArrayList(service.search(query, options).scroll()); - return new PagedResult(rules, PagingResult.create(Integer.MAX_VALUE, 1, rules.size())); + QueryOptions options = new QueryOptions(); + Integer page = RubyUtils.toInteger(params.get("p")); + int pageIndex = page != null ? page : 1; + Integer pageSize = RubyUtils.toInteger(params.get("pageSize")); + options.setPage(pageIndex, pageSize != null ? pageSize : 50); + + Result result = service.search(query, options); + return new PagedResult(result.getHits(), PagingResult.create(options.getLimit(), pageIndex, result.getTotal())); } /** -- 2.39.5