Module: FullSearch::BulkImport
- Defined in:
- lib/full_search/bulk_import.rb
Class Method Summary collapse
- .bulk_import(model) ⇒ Object
- .bulk_importing?(model) ⇒ Boolean
- .end_bulk_import(model) ⇒ Object
- .start_bulk_import(model) ⇒ Object
Class Method Details
.bulk_import(model) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/full_search/bulk_import.rb', line 6 def bulk_import(model) start_bulk_import(model) yield ensure end_bulk_import(model) end |
.bulk_importing?(model) ⇒ Boolean
37 38 39 |
# File 'lib/full_search/bulk_import.rb', line 37 def bulk_importing?(model) models_in_bulk_import.include?(model) end |
.end_bulk_import(model) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/full_search/bulk_import.rb', line 18 def end_bulk_import(model) models_in_bulk_import.delete(model) FullSearch::Index.create_triggers!(model) FullSearch::BackfillJob.perform_later(model.name) rescue => e # Triggers are still dropped at this point; the FTS index will rot on # every subsequent write. Retry once, then raise loudly so the caller # knows the index is compromised instead of failing silent. retry_count = (Thread.current[:_fs_bulk_import_retry] ||= 0) if retry_count < 1 Thread.current[:_fs_bulk_import_retry] = retry_count + 1 retry end raise FullSearch::TriggerRestoreError, "Failed to restore FTS triggers for #{model.table_name} after bulk import: #{e.}" ensure Thread.current[:_fs_bulk_import_retry] = nil end |
.start_bulk_import(model) ⇒ Object
13 14 15 16 |
# File 'lib/full_search/bulk_import.rb', line 13 def start_bulk_import(model) models_in_bulk_import << model FullSearch::Index.drop_triggers!(model) end |