Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valkyrize Reindex jobs #2173

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ class SitesController < ApplicationController
def update
# FIXME: Pull these strings out to i18n locale
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:)
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:)
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:)
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:)
works.each do |w|
ReindexItemJob.perform_later(w.id.to_s)
end
end
end
Expand Down
Loading