Make it configurable after how many chars suggestions are provided

Suggestions for reviewers, accounts, account groups and projects are
provided to the user as soon as he starts typing. On systems with many
accounts, account groups and projects providing suggestions may be
expensive, especially for short query strings. Suggestions for very
short query strings are often not very useful for the user because the
list of suggestions is too big. Normally useful suggestions are only
provided if the user has typed a certain number of character that is
sufficient to limit the suggestions to a reasonable set. In this case
it makes sense to show suggestions only if the user has typed a least
a certain number of characters. Allow administrators to configure after
how many typed characters suggestions should be provided. By default
suggestions will always be provided.

Change-Id: I66bc9eeee9e1f67063fcb21dca5e2c76b20e7187
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2012-10-19 20:41:18 +02:00
parent d0b433d607
commit f957dc2675
8 changed files with 61 additions and 12 deletions

View File

@@ -2288,6 +2288,13 @@ otherwise, this value applies to both `suggest.accounts` and
New configurations should prefer the boolean value for this field
and an enum value for `accounts.visibility`.
[[suggest.from]]suggest.from::
+
The number of characters that a user must have typed before suggestions
are provided. If set to 0, suggestions are always provided.
+
By default 0.
[[theme]] Section theme
~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -51,6 +51,7 @@ public class GerritConfig implements Cloneable {
protected boolean documentationAvailable;
protected boolean testChangeMerge;
protected String anonymousCowardName;
protected int suggestFrom;
public String getRegisterUrl() {
return registerUrl;
@@ -238,6 +239,14 @@ public class GerritConfig implements Cloneable {
this.anonymousCowardName = anonymousCowardName;
}
public int getSuggestFrom() {
return suggestFrom;
}
public void setSuggestFrom(final int suggestFrom) {
this.suggestFrom = suggestFrom;
}
public boolean siteHasUsernames() {
if (getAuthType() == AuthType.CUSTOM_EXTENSION
&& getHttpPasswordUrl() != null

View File

@@ -20,7 +20,6 @@ import com.google.gerrit.common.data.GroupReference;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.user.client.ui.SuggestOracle;
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
import java.util.ArrayList;
import java.util.HashMap;
@@ -28,14 +27,14 @@ import java.util.List;
import java.util.Map;
/** Suggestion Oracle for AccountGroup entities. */
public class AccountGroupSuggestOracle extends HighlightSuggestOracle {
public class AccountGroupSuggestOracle extends SuggestAfterTypingNCharsOracle {
private Map<String, AccountGroup.UUID> priorResults =
new HashMap<String, AccountGroup.UUID>();
private Project.NameKey projectName;
@Override
public void onRequestSuggestions(final Request req, final Callback callback) {
public void _onRequestSuggestions(final Request req, final Callback callback) {
RpcStatus.hide(new Runnable() {
public void run() {
SuggestUtil.SVC.suggestAccountGroupForProject(

View File

@@ -19,15 +19,14 @@ import com.google.gerrit.client.RpcStatus;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.common.data.AccountInfo;
import com.google.gwt.user.client.ui.SuggestOracle;
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
import java.util.ArrayList;
import java.util.List;
/** Suggestion Oracle for Account entities. */
public class AccountSuggestOracle extends HighlightSuggestOracle {
public class AccountSuggestOracle extends SuggestAfterTypingNCharsOracle {
@Override
public void onRequestSuggestions(final Request req, final Callback callback) {
public void _onRequestSuggestions(final Request req, final Callback callback) {
RpcStatus.hide(new Runnable() {
public void run() {
SuggestUtil.SVC.suggestAccount(req.getQuery(), Boolean.TRUE,

View File

@@ -17,12 +17,11 @@ package com.google.gerrit.client.ui;
import com.google.gerrit.client.RpcStatus;
import com.google.gerrit.client.projects.ProjectMap;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
/** Suggestion Oracle for Project.NameKey entities. */
public class ProjectNameSuggestOracle extends HighlightSuggestOracle {
public class ProjectNameSuggestOracle extends SuggestAfterTypingNCharsOracle {
@Override
public void onRequestSuggestions(final Request req, final Callback callback) {
public void _onRequestSuggestions(final Request req, final Callback callback) {
RpcStatus.hide(new Runnable() {
@Override
public void run() {

View File

@@ -22,18 +22,17 @@ import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.common.data.ReviewerInfo;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwt.user.client.ui.SuggestOracle;
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
import java.util.ArrayList;
import java.util.List;
/** Suggestion Oracle for reviewers. */
public class ReviewerSuggestOracle extends HighlightSuggestOracle {
public class ReviewerSuggestOracle extends SuggestAfterTypingNCharsOracle {
private Change.Id changeId;
@Override
protected void onRequestSuggestions(final Request req, final Callback callback) {
protected void _onRequestSuggestions(final Request req, final Callback callback) {
RpcStatus.hide(new Runnable() {
public void run() {
SuggestUtil.SVC.suggestChangeReviewer(changeId, req.getQuery(),

View File

@@ -0,0 +1,36 @@
// Copyright (C) 2012 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.ui;
import com.google.gerrit.client.Gerrit;
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
/**
* Suggest oracle that only provides suggestions if the user has typed at least
* as many characters as configured by 'suggest.from'. If 'suggest.from' is set
* to 0, suggestions will always be provided.
*/
public abstract class SuggestAfterTypingNCharsOracle extends HighlightSuggestOracle {
@Override
protected void onRequestSuggestions(final Request request, final Callback done) {
final int suggestFrom = Gerrit.getConfig().getSuggestFrom();
if (suggestFrom == 0 || request.getQuery().length() >= suggestFrom) {
_onRequestSuggestions(request, done);
}
}
protected abstract void _onRequestSuggestions(Request request, Callback done);
}

View File

@@ -121,6 +121,7 @@ class GerritConfigProvider implements Provider<GerritConfig> {
config.setTestChangeMerge(cfg.getBoolean("changeMerge",
"test", false));
config.setAnonymousCowardName(anonymousCowardName);
config.setSuggestFrom(cfg.getInt("suggest", "from", 0));
config.setReportBugUrl(cfg.getString("gerrit", null, "reportBugUrl"));
if (config.getReportBugUrl() == null) {