ListProjects: Bail out of the loop earlier

Iteration over the project states in ListProjects#display() method is
the main logic to render the project list. A number of check is
performed whether or not a specific project should be included in the
result or not. After a number of checks, including git repository
checks, the loop is bailed out if skip or limit is set and reached.

Move the check for skip and limit to earlier in the loop to avoid the
resource and time consuming checks in vain. As the side effect of this
change ProjectInfo is stopped to be populated with the data, that would
be eventually discarded anyway.

Change-Id: I4982800143b617f0d6e9d2a704002b2368249b4e
This commit is contained in:
David Ostrovsky
2019-01-24 09:37:11 +01:00
parent e252211af4
commit cc86e178a8

View File

@@ -354,12 +354,19 @@ public class ListProjects implements RestReadView<TopLevelResource> {
continue;
}
ProjectInfo info = new ProjectInfo();
if (showTree && !format.isJson()) {
treeMap.put(projectName, projectNodeFactory.create(e.getProject(), true));
continue;
}
if (foundIndex++ < start) {
continue;
}
if (limit > 0 && ++found > limit) {
break;
}
ProjectInfo info = new ProjectInfo();
info.name = projectName.get();
if (showTree && format.isJson()) {
addParentProjectInfo(hiddenNames, accessibleParents, perm, e, info);
@@ -402,13 +409,6 @@ public class ListProjects implements RestReadView<TopLevelResource> {
List<WebLinkInfo> links = webLinks.getProjectLinks(projectName.get());
info.webLinks = links.isEmpty() ? null : links;
if (foundIndex++ < start) {
continue;
}
if (limit > 0 && ++found > limit) {
break;
}
if (stdout == null || format.isJson()) {
output.put(info.name, info);
continue;