Skip to content

Commit

Permalink
Add a rake task that prioritizes solr reindexing to minimize downtime
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacall committed Dec 4, 2024
1 parent 87d8932 commit ebc50c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 21 additions & 0 deletions lib/tasks/tess.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ebc50c2

Please sign in to comment.