Skip to content

Commit

Permalink
cache calls to dataverseService.findRootDataverse() #4062
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Jun 23, 2014
1 parent 13520c1 commit c9151d4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/IndexServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class IndexServiceBean {
private static final String PUBLISHED_STRING = "Published";
private static final String UNPUBLISHED_STRING = "Unpublished";
private static final String DRAFT_STRING = "Draft";
private Dataverse rootDataverseCached;

public String indexAll() {
/**
Expand Down Expand Up @@ -118,7 +119,7 @@ public String indexAll() {
}

public String indexDataverse(Dataverse dataverse) {
Dataverse rootDataverse = dataverseService.findRootDataverse();
Dataverse rootDataverse = findRootDataverseCached();
if (dataverse.getId() == rootDataverse.getId()) {
/**
* @todo: replace hard-coded groups with real groups
Expand Down Expand Up @@ -843,7 +844,8 @@ public String indexUser(DataverseUser user) {
}

public List<String> findPathSegments(Dataverse dataverse, List<String> segments) {
if (!dataverseService.findRootDataverse().equals(dataverse)) {
Dataverse rootDataverse = findRootDataverseCached();
if (!dataverse.equals(rootDataverse)) {
// important when creating root dataverse
if (dataverse.getOwner() != null) {
findPathSegments(dataverse.getOwner(), segments);
Expand Down Expand Up @@ -996,4 +998,17 @@ private List<String> findSolrDocIdsForDraftFilesToDelete(Dataset datasetWithDraf
return solrIdsOfFilesToDelete;
}

private Dataverse findRootDataverseCached() {
if (rootDataverseCached != null) {
return rootDataverseCached;
} else {
rootDataverseCached = dataverseService.findRootDataverse();
if (rootDataverseCached != null) {
return rootDataverseCached;
} else {
throw new RuntimeException("unable to determine root dataverse");
}
}
}

}

0 comments on commit c9151d4

Please sign in to comment.