[VIVO-1399] Improve performance of Graph URI lookups

This commit is contained in:
Graham Triggs 2017-10-11 19:37:07 +01:00
parent e729fc9f38
commit 107c2bff03
4 changed files with 29 additions and 13 deletions

View file

@ -61,6 +61,9 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
protected abstract DatasetWrapper getDatasetWrapper(); protected abstract DatasetWrapper getDatasetWrapper();
protected volatile boolean rebuildGraphURICache = true;
private final List<String> graphURIs = new ArrayList<>();
@Override @Override
public abstract boolean changeSetUpdate(ChangeSet changeSet) throws RDFServiceException; public abstract boolean changeSetUpdate(ChangeSet changeSet) throws RDFServiceException;
@ -527,18 +530,28 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
@Override @Override
public List<String> getGraphURIs() throws RDFServiceException { public List<String> getGraphURIs() throws RDFServiceException {
DatasetWrapper dw = getDatasetWrapper(); if (rebuildGraphURICache) {
try { synchronized (RDFServiceJena.class) {
Dataset d = dw.getDataset(); if (rebuildGraphURICache) {
List<String> graphURIs = new ArrayList<String>(); rebuildGraphURICache = false;
Iterator<String> nameIt = d.listNames(); graphURIs.clear();
while (nameIt.hasNext()) {
graphURIs.add(nameIt.next()); DatasetWrapper dw = getDatasetWrapper();
try {
Dataset d = dw.getDataset();
Iterator<String> nameIt = d.listNames();
while (nameIt.hasNext()) {
graphURIs.add(nameIt.next());
}
return graphURIs;
} finally {
dw.close();
}
}
} }
return graphURIs;
} finally {
dw.close();
} }
return graphURIs;
} }
@Override @Override

View file

@ -110,6 +110,7 @@ public class RDFServiceSDB extends RDFServiceJena implements RDFService {
abortTransaction(sdbConn); abortTransaction(sdbConn);
throw new RDFServiceException(e); throw new RDFServiceException(e);
} finally { } finally {
rebuildGraphURICache = true;
close(sdbConn); close(sdbConn);
} }
} }

View file

@ -88,6 +88,8 @@ public class RDFServiceTDB extends RDFServiceJena {
} catch (Exception e) { } catch (Exception e) {
log.error(e, e); log.error(e, e);
throw new RDFServiceException(e); throw new RDFServiceException(e);
} finally {
rebuildGraphURICache = true;
} }
} }

View file

@ -514,7 +514,7 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
} }
} }
public void addModel(Model model, String graphURI) throws RDFServiceException { private void addModel(Model model, String graphURI) throws RDFServiceException {
try { try {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
verbModel(model, graphURI, "INSERT"); verbModel(model, graphURI, "INSERT");
@ -524,7 +524,7 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
} }
} }
public void deleteModel(Model model, String graphURI) throws RDFServiceException { private void deleteModel(Model model, String graphURI) throws RDFServiceException {
try { try {
verbModel(model, graphURI, "DELETE"); verbModel(model, graphURI, "DELETE");
} finally { } finally {