From ebc50c24c664733c45afbc199f5c9e35540e9edc Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Wed, 4 Dec 2024 15:22:33 +0000 Subject: [PATCH] Add a rake task that prioritizes solr reindexing to minimize downtime --- docs/docker.md | 4 ++-- docs/install.md | 2 +- lib/tasks/tess.rake | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/docs/docker.md b/docs/docker.md index eb039e7f5..63dcf29ef 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -69,7 +69,7 @@ To run a specific test, you can override the command being passed: To force Solr to reindex all documents, you can run the following command: - docker-compose exec app bundle exec rake sunspot:reindex + docker-compose exec app bundle exec rake tess:reindex ### Additional development commands @@ -134,4 +134,4 @@ Precompile the assets, necessary if any CSS/JS/images are changed after building Reindex Solr: - docker-compose -f docker-compose-prod.yml exec app bundle exec rake sunspot:reindex + docker-compose -f docker-compose-prod.yml exec app bundle exec rake tess:reindex diff --git a/docs/install.md b/docs/install.md index 9b4fd5bfe..b1134eb79 100644 --- a/docs/install.md +++ b/docs/install.md @@ -154,7 +154,7 @@ Next, create a collection for TeSS to use (assuming TeSS is checked out at `/hom If you ever need to re-index your TeSS data, for example if you have existing data in your TeSS database and are using a new collection, you can run the following command: - bundle exec rake seek:reindex_all + bundle exec rake tess:reindex ## Redis/Sidekiq diff --git a/lib/tasks/tess.rake b/lib/tasks/tess.rake index 6ab3336f5..b9ea67ee0 100644 --- a/lib/tasks/tess.rake +++ b/lib/tasks/tess.rake @@ -261,4 +261,25 @@ namespace :tess do puts 'Done' end + + desc 'Rebuild search index, prioritizing more frequently searched resources (upcoming events, materials)' + task reindex: :environment do + puts "Rebuilding search index..." + Rails.application.eager_load! + Event.solr_remove_all_from_index + print " Reindexing #{Event.not_finished.count} upcoming events... " + Event.not_finished.solr_index + puts "done" + prioritized = [Material, Collection, ContentProvider] | Sunspot.searchable.to_a + prioritized.each do |model| + next if model.name == 'Event' + print " Reindexing #{model.count} #{model.model_name.human.pluralize}... " + model.solr_reindex + puts "done" + end + print " Reindexing #{Event.finished.count} past events... " + Event.finished.solr_index + puts "done" + puts "Finished!" + end end