From 46839d8e4663d2736edab0278376f08d1d9d05ed Mon Sep 17 00:00:00 2001 From: Sebastian Hofmann <7668803+sebhofmann@users.noreply.github.com> Date: Fri, 23 Feb 2024 14:01:44 +0100 Subject: [PATCH] MCR-3049 prevent unnecessary indexing of mods child documents by checking a property (#2075) * MCR-3049 prevent unnecessary indexing of mods child documents by checking a property * MCR-3049 better TODO message --- .../org/mycore/mods/MCRMODSLinksEventHandler.java | 13 ++++++++++--- .../components/mods/config/mycore.properties | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mycore-mods/src/main/java/org/mycore/mods/MCRMODSLinksEventHandler.java b/mycore-mods/src/main/java/org/mycore/mods/MCRMODSLinksEventHandler.java index c2a1b01a2e..d7572e8e8d 100644 --- a/mycore-mods/src/main/java/org/mycore/mods/MCRMODSLinksEventHandler.java +++ b/mycore-mods/src/main/java/org/mycore/mods/MCRMODSLinksEventHandler.java @@ -23,6 +23,7 @@ import org.jdom2.Element; import org.mycore.common.MCRConstants; +import org.mycore.common.config.MCRConfiguration2; import org.mycore.common.events.MCREvent; import org.mycore.common.events.MCREventHandlerBase; import org.mycore.common.events.MCREventManager; @@ -42,6 +43,11 @@ */ public class MCRMODSLinksEventHandler extends MCREventHandlerBase { + public static final String INDEX_ALL_CHILDREN_PROPERTY_NAME = "MCR.MODS.LinksEventHandler.IndexAllChildren"; + private static final boolean INDEX_ALL_CHILDREN + = MCRConfiguration2.getBoolean(INDEX_ALL_CHILDREN_PROPERTY_NAME) + .orElseThrow(() -> MCRConfiguration2.createConfigurationException(INDEX_ALL_CHILDREN_PROPERTY_NAME)); + /* (non-Javadoc) * @see org.mycore.common.events.MCREventHandlerBase * #handleObjectCreated(org.mycore.common.events.MCREvent, org.mycore.datamodel.metadata.MCRObject) @@ -87,11 +93,12 @@ protected void handleObjectUpdated(final MCREvent evt, final MCRObject obj) { } handleObjectCreated(evt, obj); //may have to reindex children, if they inherit any information + // TODO: remove this code, it is not part of this classes responsibility. if information is inherited, i.e. + // because of a metadata share agent, that process should, in turn, cause a reindexing of affected objects for (MCRMetaLinkID childLinkID : obj.getStructure().getChildren()) { MCRObjectID childID = childLinkID.getXLinkHrefID(); - if (MCRMetadataManager.exists(childID)) { - MCREvent childEvent - = new MCREvent(MCREvent.ObjectType.OBJECT, MCREvent.EventType.INDEX); + if (MCRMetadataManager.exists(childID) && INDEX_ALL_CHILDREN) { + MCREvent childEvent = new MCREvent(MCREvent.ObjectType.OBJECT, MCREvent.EventType.INDEX); childEvent.put(MCREvent.OBJECT_KEY, MCRMetadataManager.retrieve(childID)); MCREventManager.instance().handleEvent(childEvent); } diff --git a/mycore-mods/src/main/resources/components/mods/config/mycore.properties b/mycore-mods/src/main/resources/components/mods/config/mycore.properties index da6adb66ae..fed4c34da8 100644 --- a/mycore-mods/src/main/resources/components/mods/config/mycore.properties +++ b/mycore-mods/src/main/resources/components/mods/config/mycore.properties @@ -239,3 +239,6 @@ MCR.ContentTransformer.migrate-extension-display.Class=org.mycore.common.content MCR.ContentTransformer.migrate-extension-display.TransformerFactoryClass=net.sf.saxon.TransformerFactoryImpl MCR.ContentTransformer.migrate-extension-display.Stylesheet=xsl/migrate-extension-display.xsl +# if somebody wants to index all children of a mods object without checking if their metadata is changed, +# then the following property can be set to true +MCR.MODS.LinksEventHandler.IndexAllChildren=false