Remove unneccessary second Context in RDFConsumer

fixes #8152
This commit is contained in:
Pascal-Nicolas Becker
2022-02-07 23:13:35 +01:00
parent 7af52a0883
commit f0a6b51f34

View File

@@ -317,26 +317,25 @@ public class RDFConsumer implements Consumer
@Override @Override
public void end(Context ctx) throws Exception { public void end(Context ctx) throws Exception {
log.debug("Started processing of queued events."); log.debug("Started processing of queued events.");
// create a new context, to be sure to work as anonymous user // store the context mode, set context read only for performance reasons, and restore the old mode
// we don't want to store private data in a triplestore with public Context.Mode oldMode = ctx.getCurrentMode();
// SPARQL endpoint. try {
ctx = new Context(Context.Mode.READ_ONLY); ctx.setMode(Context.Mode.READ_ONLY);
if (toDelete == null) if (toDelete == null) {
{
log.debug("Deletion queue does not exists, creating empty queue."); log.debug("Deletion queue does not exists, creating empty queue.");
this.toDelete = new LinkedList<>(); this.toDelete = new LinkedList<>();
} }
if (toConvert != null) if (toConvert != null) {
{
log.debug("Starting conversion of DSpaceObjects."); log.debug("Starting conversion of DSpaceObjects.");
while (true) while (true) {
{
DSOIdentifier id; DSOIdentifier id;
try { id = toConvert.removeFirst(); } try {
catch (NoSuchElementException ex) { break; } id = toConvert.removeFirst();
} catch (NoSuchElementException ex) {
break;
}
if (toDelete.contains(id)) if (toDelete.contains(id)) {
{
log.debug("Skipping " + Constants.typeText[id.type] + " " log.debug("Skipping " + Constants.typeText[id.type] + " "
+ id.id.toString() + " as it is marked for " + id.id.toString() + " as it is marked for "
+ "deletion as well."); + "deletion as well.");
@@ -349,18 +348,23 @@ public class RDFConsumer implements Consumer
log.debug("Conversion ended."); log.debug("Conversion ended.");
} }
log.debug("Starting to delete data from the triple store..."); log.debug("Starting to delete data from the triple store...");
while (true) while (true) {
{
DSOIdentifier id; DSOIdentifier id;
try { id = toDelete.removeFirst(); } try {
catch (NoSuchElementException ex) { break; } id = toDelete.removeFirst();
} catch (NoSuchElementException ex) {
break;
}
log.debug("Going to delete data from " + log.debug("Going to delete data from " +
Constants.typeText[id.type] + " " Constants.typeText[id.type] + " "
+ id.id.toString() + "."); + id.id.toString() + ".");
delete(ctx, id); delete(ctx, id);
} }
ctx.abort(); } finally {
// restore context mode
ctx.setMode(oldMode);
}
log.debug("Deletion finished."); log.debug("Deletion finished.");
} }