Introduce query change query option SKIP_MERGEABLE

With this option, the mergeable field is not set. For chromium, the
cached data for this field is frequently out of date, and recomputing
it costs several seconds. This change allows the UI to populate the
'submit' button asynchronously, thereby speeding up the page load.

Change-Id: I5c922efe301dcf34379a7e5c1ac9133e7e1bf841
This commit is contained in:
Han-Wen Nienhuys
2018-01-16 13:15:38 +01:00
parent 0a9994fab9
commit 19de6cd065
4 changed files with 26 additions and 3 deletions

View File

@@ -301,6 +301,12 @@ default. Optional fields are:
link:user-search.html#reviewedby[reviewedby:self].
--
[[skip_mergeable]]
--
* `SKIP_MERGEABLE`: skip the `mergeable` field in
link:#change-info[ChangeInfo]. For fast moving projects, this field must
be recomputed often, which is slow for projects with big trees.
[[submittable]]
--
* `SUBMITTABLE`: include the `submittable` field in link:#change-info[ChangeInfo],
@@ -5658,7 +5664,8 @@ The link:project-configuration.html#submit_type[submit type] of the change. +
Not set for merged changes.
|`mergeable` |optional|
Whether the change is mergeable. +
Not set for merged changes, or if the change has not yet been tested.
Not set for merged changes, if the change has not yet been tested, or
if the link:#skip_mergeable[skip_mergeable] option is set.
|`submittable` |optional|
Whether the change has been approved by the project submit rules. +
Only set if link:#submittable[requested].

View File

@@ -75,7 +75,10 @@ public enum ListChangesOption {
SUBMITTABLE(20),
/** If tracking Ids are included, include detailed tracking Ids info. */
TRACKING_IDS(21);
TRACKING_IDS(21),
/** Skip mergeability data */
SKIP_MERGEABLE(22);
private final int value;

View File

@@ -33,6 +33,7 @@ import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
import static com.google.gerrit.extensions.client.ListChangesOption.PUSH_CERTIFICATES;
import static com.google.gerrit.extensions.client.ListChangesOption.REVIEWED;
import static com.google.gerrit.extensions.client.ListChangesOption.REVIEWER_UPDATES;
import static com.google.gerrit.extensions.client.ListChangesOption.SKIP_MERGEABLE;
import static com.google.gerrit.extensions.client.ListChangesOption.SUBMITTABLE;
import static com.google.gerrit.extensions.client.ListChangesOption.TRACKING_IDS;
import static com.google.gerrit.extensions.client.ListChangesOption.WEB_LINKS;
@@ -521,7 +522,9 @@ public class ChangeJson {
if (str.isOk()) {
out.submitType = str.type;
}
out.mergeable = cd.isMergeable();
if (!has(SKIP_MERGEABLE)) {
out.mergeable = cd.isMergeable();
}
if (has(SUBMITTABLE)) {
out.submittable = submittable(cd);
}

View File

@@ -91,6 +91,7 @@ import com.google.gerrit.extensions.client.ChangeKind;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.Comment.Range;
import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.extensions.client.SubmitType;
@@ -236,6 +237,15 @@ public class ChangeIT extends AbstractDaemonTest {
assertThat(c.owner.avatars).isNull();
}
@Test
public void skipMergeable() throws Exception {
PushOneCommit.Result r = createChange();
String triplet = project.get() + "~master~" + r.getChangeId();
ChangeInfo c =
gApi.changes().id(triplet).get(ImmutableList.of(ListChangesOption.SKIP_MERGEABLE));
assertThat(c.mergeable).isNull();
}
@Test
public void setPrivateByOwner() throws Exception {
TestRepository<InMemoryRepository> userRepo = cloneProject(project, user);