Skip to content

Commit

Permalink
MCR-3049 prevent unnecessary indexing of mods child documents by chec…
Browse files Browse the repository at this point in the history
…king a property (#2075)

* MCR-3049 prevent unnecessary indexing of mods child documents by checking a property

* MCR-3049 better TODO message
  • Loading branch information
sebhofmann authored Feb 23, 2024
1 parent 2135439 commit 46839d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 46839d8

Please sign in to comment.