Avoid empty web_links element inside of RevisionInfo
Web UI always requests WEB_LINKS from /changes/{id}, but the common case for a server is to have no special PatchSetWebLink. Skip the "web_links = []" JSON code that appears in every revision on the change by setting the list to null. Skip pointless copying of the computed collection by changing the return type from WebLinks to clearly be a List<WebLinkInfo>, like RevisionInfo expects. This allows direct assignment into the result. Change-Id: I665e225b5abdd571a0adba8d2a1d318a1926801a
This commit is contained in:
@@ -24,6 +24,7 @@ import com.google.gerrit.extensions.webui.ProjectWebLink;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
@@ -45,8 +46,8 @@ public class WebLinks {
|
||||
this.branchLinks = branchLinks;
|
||||
}
|
||||
|
||||
public Iterable<WebLinkInfo> getPatchSetLinks(String project, String commit) {
|
||||
List<WebLinkInfo> links = Lists.newArrayList();
|
||||
public List<WebLinkInfo> getPatchSetLinks(String project, String commit) {
|
||||
List<WebLinkInfo> links = new ArrayList<>(4);
|
||||
for (PatchSetWebLink webLink : patchSetLinks) {
|
||||
links.add(new WebLinkInfo(webLink.getLinkName(),
|
||||
webLink.getImageUrl(),
|
||||
|
@@ -843,11 +843,9 @@ public class ChangeJson {
|
||||
}
|
||||
|
||||
if (has(WEB_LINKS)) {
|
||||
out.webLinks = Lists.newArrayList();
|
||||
for (WebLinkInfo link : webLinks.getPatchSetLinks(
|
||||
project, in.getRevision().get())) {
|
||||
out.webLinks.add(link);
|
||||
}
|
||||
List<WebLinkInfo> links =
|
||||
webLinks.getPatchSetLinks(project, in.getRevision().get());
|
||||
out.webLinks = !links.isEmpty() ? links : null;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
Reference in New Issue
Block a user