From c9151d4c1f7b3364f1d7e999a279686708c07fc5 Mon Sep 17 00:00:00 2001 From: Philip Durbin Date: Mon, 23 Jun 2014 14:53:58 -0400 Subject: [PATCH] cache calls to dataverseService.findRootDataverse() #4062 --- .../iq/dataverse/IndexServiceBean.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/IndexServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/IndexServiceBean.java index 92077ce0a0e..700a5a64ae3 100644 --- a/src/main/java/edu/harvard/iq/dataverse/IndexServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/IndexServiceBean.java @@ -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() { /** @@ -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 @@ -843,7 +844,8 @@ public String indexUser(DataverseUser user) { } public List findPathSegments(Dataverse dataverse, List 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); @@ -996,4 +998,17 @@ private List 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"); + } + } + } + }