Browse files

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.
  • Loading branch information...
jrochkind committed Nov 13, 2017
1 parent a6fa4a5 commit fbaca9d3dff19efb0f1aebbeaffccfe6a0b26025
Showing with 22 additions and 4 deletions.
  1. +22 −4 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.
# 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 = 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.
super.tap do
# Got here without an error? Trigger DZI creation
# reindex the fileset, cause we added things to it, so it needs reindexing.
# 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.parent.representative_id ==
# Trigger DZI creation in bg job
if CHF::Env.lookup(:dzi_auto_create)
CreateDziJob.perform_later(, repo_file_type: type.to_s)

0 comments on commit fbaca9d

Please sign in to comment.