Move AccountLimits usage out of QueryProcessor
We want to move QueryProcessor to the index package, which means it cannot depend on this piece of core Gerrit. Move the lazy computation into an IntSupplier that can be created at subclass construction time, and add a method to AccountLimits to limit repetition. Clarify the documentation around the different kinds of limits. Change-Id: Iac182571944d0c648f1bc1d2669566170c81f2d4
This commit is contained in:
@@ -21,6 +21,7 @@ import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.git.QueueProvider;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.query.QueryProcessor;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
@@ -89,6 +90,15 @@ public class AccountLimits {
|
||||
return QueueProvider.QueueType.INTERACTIVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the limit on a {@link QueryProcessor} for a given user.
|
||||
*
|
||||
* @return limit according to {@link GlobalCapability#QUERY_LIMIT}.
|
||||
*/
|
||||
public int getQueryLimit() {
|
||||
return getRange(GlobalCapability.QUERY_LIMIT).getMax();
|
||||
}
|
||||
|
||||
/** @return true if the user has a permission rule specifying the range. */
|
||||
public boolean hasExplicitRange(String permission) {
|
||||
return GlobalCapability.hasRange(permission) && !getRules(permission).isEmpty();
|
||||
|
@@ -71,7 +71,7 @@ public class QueryAccounts implements RestReadView<TopLevelResource> {
|
||||
usage = "maximum number of users to return"
|
||||
)
|
||||
public void setLimit(int n) {
|
||||
queryProcessor.setLimit(n);
|
||||
queryProcessor.setUserProvidedLimit(n);
|
||||
|
||||
if (n < 0) {
|
||||
suggestLimit = 10;
|
||||
@@ -177,7 +177,7 @@ public class QueryAccounts implements RestReadView<TopLevelResource> {
|
||||
Predicate<AccountState> queryPred;
|
||||
if (suggest) {
|
||||
queryPred = queryBuilder.defaultQuery(query);
|
||||
queryProcessor.setLimit(suggestLimit);
|
||||
queryProcessor.setUserProvidedLimit(suggestLimit);
|
||||
} else {
|
||||
queryPred = queryBuilder.parse(query);
|
||||
}
|
||||
|
Reference in New Issue
Block a user