From a39cb382a09993e9597d0eba41c78ba130216e42 Mon Sep 17 00:00:00 2001 From: Patrick Hiesel Date: Mon, 23 Apr 2018 19:22:44 +0200 Subject: [PATCH] Ensure SubmitRecords are loaded in SubmittedTogether LocalMergeSuperSet uses InternalChangeQuery to get byCommitsOnBranchNotMerged. When the number of search terms exceeds the limit, changes are loaded from the database. This means, that submitRecords and currentPatchSet are not populated. Since we set lazyload for ChangeJson, these fields can be empty when we format the JSON response. Since maxNumTerms is large, this bug happens very rarely. This change is a stop-gap until we implement a better solution. Change-Id: Ica1b01ea45f086b58501040cb6e5bfd0bbaa76b8 --- .../server/restapi/change/SubmittedTogether.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/java/com/google/gerrit/server/restapi/change/SubmittedTogether.java b/java/com/google/gerrit/server/restapi/change/SubmittedTogether.java index 46c8cbce87..bbfe75d3ab 100644 --- a/java/com/google/gerrit/server/restapi/change/SubmittedTogether.java +++ b/java/com/google/gerrit/server/restapi/change/SubmittedTogether.java @@ -135,7 +135,7 @@ public class SubmittedTogether implements RestReadView { if (c.getStatus().isOpen()) { ChangeSet cs = mergeSuperSet.get().completeChangeSet(dbProvider.get(), c, resource.getUser()); - cds = cs.changes().asList(); + cds = ensureRequiredDataIsLoaded(cs.changes().asList()); hidden = cs.nonVisibleChanges().size(); } else if (c.getStatus().asChangeStatus() == ChangeStatus.MERGED) { cds = queryProvider.get().bySubmissionId(c.getSubmissionId()); @@ -184,4 +184,18 @@ public class SubmittedTogether implements RestReadView { } return sorted; } + + private static List ensureRequiredDataIsLoaded(List cds) + throws OrmException { + // TODO(hiesel): Instead of calling these manually, either implement a helper that brings a + // database-backed change on-par with an index-backed change in terms of the populated fields in + // ChangeData or check if any of the ChangeDatas was loaded from the database and allow + // lazyloading if so. + for (ChangeData cd : cds) { + cd.submitRecords(ChangeJson.SUBMIT_RULE_OPTIONS_LENIENT); + cd.submitRecords(ChangeJson.SUBMIT_RULE_OPTIONS_STRICT); + cd.currentPatchSet(); + } + return cds; + } }