Skip to content

Commit

Permalink
🎁 Valkyrize Reindex jobs
Browse files Browse the repository at this point in the history
Addresses all reindex jobs to ensure that they will work for
either valkyrie or active fedora objects.

Ensures that works and collections are appropriately reindexed aborts
default work and collection images are added OR removed (previously,
reindexing didn't occur with removal of default images, resulting in
works displaying with a missing image.)
  • Loading branch information
laritakr committed Mar 30, 2024
1 parent 093251b commit 7779fc7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 10 deletions.
15 changes: 14 additions & 1 deletion app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ class SitesController < ApplicationController

def update
# FIXME: Pull these strings out to i18n locale
if @site.update(update_params)
if @site.update(update_params)

# If updating work or collection default image, works and/or collections should be reindexed
# as they are when the default image is added. See AppearancesControllerDecorator#update
if update_params['remove_default_collection_image']
# Reindex all Collections and AdminSets to apply new default collection image
ReindexCollectionsJob.perform_later
ReindexAdminSetsJob.perform_later
end

if update_params['remove_default_work_image']
# Reindex all Works to apply new default work image
ReindexWorksJob.perform_later
end
remove_appearance_text(update_params)
redirect_to hyrax.admin_appearance_path, notice: 'The appearance was successfully updated.'
else
Expand Down
13 changes: 12 additions & 1 deletion app/jobs/reindex_admin_sets_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

class ReindexAdminSetsJob < ApplicationJob
def perform
AdminSet.find_each(&:update_index)
models = Hyrax::ModelRegistry.admin_set_classes
unique_models = []
models.each do |model|
unique_models << Wings::ModelRegistry.lookup(model)
end

unique_models.uniq.each do |model|
admin_sets = Hyrax.query_service.find_all_of_model(model: model)
admin_sets.each do |as|
ReindexItemJob.perform_later(as.id.to_s)
end
end
end
end
13 changes: 11 additions & 2 deletions app/jobs/reindex_collections_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

class ReindexCollectionsJob < ApplicationJob
def perform
Collection.find_each do |collection|
ReindexItemJob.perform_later(collection)
models = Hyrax::ModelRegistry.collection_classes
unique_models = []
models.each do |model|
unique_models << Wings::ModelRegistry.lookup(model)
end

unique_models.uniq.each do |model|
collections = Hyrax.query_service.find_all_of_model(model: model)
collections.each do |coll|
ReindexItemJob.perform_later(coll.id.to_s)
end
end
end
end
13 changes: 11 additions & 2 deletions app/jobs/reindex_file_sets_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

class ReindexFileSetsJob < ApplicationJob
def perform
FileSet.find_each do |file_set|
ReindexItemJob.perform_later(file_set)
models = Hyrax::ModelRegistry.file_set_classes
unique_models = []
models.each do |model|
unique_models << Wings::ModelRegistry.lookup(model)
end

unique_models.uniq.each do |model|
file_sets = Hyrax.query_service.find_all_of_model(model: model)
file_sets.each do |fs|
ReindexItemJob.perform_later(fs.id.to_s)
end
end
end
end
4 changes: 3 additions & 1 deletion app/jobs/reindex_item_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

class ReindexItemJob < ApplicationJob
def perform(item)
def perform(item_id)
item = Hyrax.query_service.find_by(id: item_id)

if item.is_a?(Valkyrie::Resource)
Hyrax.index_adapter.save(resource: item)
else
Expand Down
16 changes: 13 additions & 3 deletions app/jobs/reindex_works_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ def perform(work = nil)
work.update_index
end
else
Site.instance.available_works.each do |work_type|
work_type.constantize.find_each do |w|
ReindexItemJob.perform_later(w)
# previously this used models = Site.instance.available_works
# however, this means that if we stop allowing a particular work
# class for a tenant, we would also not ever reindex it.
# It is safer to use all work classes.
models = Hyrax::ModelRegistry.work_classes
unique_models = []
models.each do |model|
unique_models << Wings::ModelRegistry.lookup(model)
end
unique_models.uniq.each do |model|
works = Hyrax.query_service.find_all_of_model(model: model)
works.each do |w|
ReindexItemJob.perform_later(w.id.to_s)
end
end
end
Expand Down

0 comments on commit 7779fc7

Please sign in to comment.