Skip to content

Commit

Permalink
#1059 - Removing last remaining occurrences of manual server-side pag…
Browse files Browse the repository at this point in the history
…ination. Changed remaining executeResultList to use executeList instead.
  • Loading branch information
stevespringett committed Aug 21, 2021
1 parent 2b3e8d4 commit bd0a343
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public PaginatedResult getComponents() {
public List<Component> getAllComponents() {
final Query<Component> query = pm.newQuery(Component.class);
query.setOrdering("id asc");
return query.executeResultList(Component.class);
return query.executeList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public List<Policy> getAllPolicies() {
if (orderBy == null) {
query.setOrdering("name asc");
}
return query.executeResultList(Policy.class);
return query.executeList();
}

/**
Expand Down Expand Up @@ -190,7 +190,7 @@ public List<PolicyViolation> getAllPolicyViolations() {
if (orderBy == null) {
query.setOrdering("timestamp desc, project.name, project.version, component.name, component.version");
}
return query.executeResultList(PolicyViolation.class);
return query.executeList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public List<Project> getAllProjects(boolean excludeInactive) {
query.setFilter("active == true || active == null");
}
query.setOrdering("name asc");
return query.executeResultList(Project.class);
return query.executeList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public PaginatedResult getRepositories() {
public List<Repository> getAllRepositories() {
final Query<Repository> query = pm.newQuery(Repository.class);
query.setOrdering("type asc, identifier asc");
return query.executeResultList(Repository.class);
return query.executeList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public ServiceComponent createServiceComponent(ServiceComponent service, boolean
public List<ServiceComponent> getAllServiceComponents() {
final Query<ServiceComponent> query = pm.newQuery(ServiceComponent.class);
query.setOrdering("id asc");
return query.executeResultList(ServiceComponent.class);
return query.executeList();
}

/**
Expand Down
35 changes: 8 additions & 27 deletions src/main/java/org/dependencytrack/search/ComponentIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
import alpine.logging.Logger;
import alpine.notification.Notification;
import alpine.notification.NotificationLevel;
import alpine.persistence.PaginatedResult;
import alpine.resources.AlpineRequest;
import alpine.resources.OrderDirection;
import alpine.resources.Pagination;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.Term;
Expand Down Expand Up @@ -119,30 +115,15 @@ public void remove(final Component component) {
public void reindex() {
LOGGER.info("Starting reindex task. This may take some time.");
super.reindex();
final AlpineRequest alpineRequest = new AlpineRequest(
null,
new Pagination(Pagination.Strategy.OFFSET, 0, 100),
null,
"id",
OrderDirection.ASCENDING
);
try (final QueryManager qm = new QueryManager(alpineRequest)) {
final PaginatedResult result = qm.getProjects(false, true);
long count = 0;
boolean shouldContinue = true;
while (count < result.getTotal() && shouldContinue) {
for (final Project project: result.getList(Project.class)) {
final List<Component> components = qm.getAllComponents(project);
LOGGER.info("Indexing " + components.size() + " components in project: " + project.getUuid());
for (final Component component: components) {
add(component);
}
LOGGER.info("Completed indexing of " + components.size() + " components in project: " + project.getUuid());
try (final QueryManager qm = new QueryManager()) {
final List<Project> projects = qm.getAllProjects(true);
for (final Project project : projects) {
final List<Component> components = qm.getAllComponents(project);
LOGGER.info("Indexing " + components.size() + " components in project: " + project.getUuid());
for (final Component component: components) {
add(component);
}
int lastResult = result.getObjects().size();
count += lastResult;
shouldContinue = lastResult > 0;
qm.advancePagination();
LOGGER.info("Completed indexing of " + components.size() + " components in project: " + project.getUuid());
}
commit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
import alpine.event.framework.Event;
import alpine.event.framework.Subscriber;
import alpine.logging.Logger;
import alpine.persistence.PaginatedResult;
import alpine.resources.AlpineRequest;
import alpine.resources.OrderDirection;
import alpine.resources.Pagination;
import org.apache.commons.collections4.CollectionUtils;
import org.dependencytrack.event.InternalAnalysisEvent;
import org.dependencytrack.event.MetricsUpdateEvent;
Expand Down Expand Up @@ -75,28 +71,13 @@ public void inform(final Event e) {
performPolicyEvaluation(event.getProject(), components);
} else {
LOGGER.info("Analyzing portfolio");
final AlpineRequest alpineRequest = new AlpineRequest(
null,
new Pagination(Pagination.Strategy.OFFSET, 0, 100),
null,
"id",
OrderDirection.ASCENDING
);
try (final QueryManager qm = new QueryManager(alpineRequest)) {
final PaginatedResult result = qm.getProjects(false, true);
long count = 0;
boolean shouldContinue = true;
while (count < result.getTotal() && shouldContinue) {
for (final Project project: result.getList(Project.class)) {
final List<Component> components = qm.getAllComponents(project);
LOGGER.info("Analyzing " + components.size() + " components in project: " + project.getUuid());
analyzeComponents(qm, components);
LOGGER.info("Completed analysis of " + components.size() + " components in project: " + project.getUuid());
}
int lastResult = result.getObjects().size();
count += lastResult;
shouldContinue = lastResult > 0;
qm.advancePagination();
try (final QueryManager qm = new QueryManager()) {
final List<Project> projects = qm.getAllProjects(true);
for (final Project project: projects) {
final List<Component> components = qm.getAllComponents(project);
LOGGER.info("Analyzing " + components.size() + " components in project: " + project.getUuid());
analyzeComponents(qm, components);
LOGGER.info("Completed analysis of " + components.size() + " components in project: " + project.getUuid());
}
}
LOGGER.info("Portfolio analysis complete");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
import alpine.event.framework.Event;
import alpine.event.framework.Subscriber;
import alpine.logging.Logger;
import alpine.persistence.PaginatedResult;
import alpine.resources.AlpineRequest;
import alpine.resources.OrderDirection;
import alpine.resources.Pagination;
import org.apache.commons.lang3.StringUtils;
import org.dependencytrack.event.RepositoryMetaEvent;
import org.dependencytrack.model.Component;
Expand Down Expand Up @@ -53,30 +49,15 @@ public void inform(final Event e) {
analyze(qm, qm.getObjectById(Component.class, event.getComponent().getId()));
}
} else {
final AlpineRequest alpineRequest = new AlpineRequest(
null,
new Pagination(Pagination.Strategy.OFFSET, 0, 100),
null,
"id",
OrderDirection.ASCENDING
);
try (final QueryManager qm = new QueryManager(alpineRequest)) {
final PaginatedResult result = qm.getProjects(false, true);
long count = 0;
boolean shouldContinue = true;
while (count < result.getTotal() && shouldContinue) {
for (final Project project: result.getList(Project.class)) {
final List<Component> components = qm.getAllComponents(project);
LOGGER.info("Performing component repository metadata analysis against " + components.size() + " components in project: " + project.getUuid());
for (final Component component: components) {
analyze(qm, component);
}
LOGGER.info("Completed component repository metadata analysis against " + components.size() + " components in project: " + project.getUuid());
try (final QueryManager qm = new QueryManager()) {
final List<Project> projects = qm.getAllProjects(true);
for (final Project project: projects) {
final List<Component> components = qm.getAllComponents(project);
LOGGER.info("Performing component repository metadata analysis against " + components.size() + " components in project: " + project.getUuid());
for (final Component component: components) {
analyze(qm, component);
}
int lastResult = result.getObjects().size();
count += lastResult;
shouldContinue = lastResult > 0;
qm.advancePagination();
LOGGER.info("Completed component repository metadata analysis against " + components.size() + " components in project: " + project.getUuid());
}
}
LOGGER.info("Portfolio component repository metadata analysis complete");
Expand Down

0 comments on commit bd0a343

Please sign in to comment.