From fbaca9d3dff19efb0f1aebbeaffccfe6a0b26025 Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Mon, 13 Nov 2017 16:10:00 -0500 Subject: [PATCH] AddFileToFileSet should trigger reindex of parent if representative This used to happen in the derivatives creation job. That was the wrong place for it (regenerating derivaties should not cause expensiev reindex). Removed it there -- it broke batch upload. Adding it here where it belongs. --- .../works/add_file_to_file_set_override.rb | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/overrides/hydra/works/add_file_to_file_set_override.rb b/app/overrides/hydra/works/add_file_to_file_set_override.rb index b273a124..bc244af8 100644 --- a/app/overrides/hydra/works/add_file_to_file_set_override.rb +++ b/app/overrides/hydra/works/add_file_to_file_set_override.rb @@ -1,16 +1,34 @@ -# Override and call super on #call to hook into "do this only after file is -# actually added to fedora" Can't find a better way to do that. +# Doing two things in override: + +# 1. Override and call super on #call to hook into "do this only after file is +# actually added to fedora", to trigger DZI creation. Can't find a better way to do that. # # https://bibwild.wordpress.com/2017/07/11/on-hooking-into-sufiahyrax-after-file-has-been-uploaded/ # +# +# 2. reindex the fileset after adding a file to it. It's characteristics have changed, so +# may need reindex. Plus, if this fileset is marked representative of a parent work, reindex +# the parent work too. +# In the default stack, create derivatives action triggered these reindexes, +# but that wasn't the right place (sometimes doing unneccesary +# reindexes on bulk deriv creation), this is. Hydra::Works::AddFileToFileSet.class_eval do AddFileToFileSetClassOverrides = Module.new do def call(file_set, file, type, update_existing: true, versioning: true) - # super at hydra-works 0.16.0 when implemented. + # when we implemented, super was in hydra-works 0.16.0. # https://github.com/samvera/hydra-works/blob/v0.16.0/lib/hydra/works/services/add_file_to_file_set.rb#L10 super.tap do - # Got here without an error? Trigger DZI creation + # reindex the fileset, cause we added things to it, so it needs reindexing. + file_set.update_index + + # If this file_set is the thumbnail for the parent work, + # then the parent also needs to be reindexed. + if file_set.parent && (file_set.parent.thumbnail_id == file_set.id || file_set.parent.representative_id == file_set.id) + file_set.parent.update_index + end + + # Trigger DZI creation in bg job if CHF::Env.lookup(:dzi_auto_create) CreateDziJob.perform_later(file_set.id, repo_file_type: type.to_s) end