From 97d9015e13f9ef46650e798009aa5ee7c8dd43d4 Mon Sep 17 00:00:00 2001 From: Alberto Espinoza Date: Tue, 15 Oct 2024 18:26:29 -0600 Subject: [PATCH 1/2] R2-3054 Fix periodic_job initializer --- config/initializers/{solr.rb => enable_solr.rb} | 0 config/initializers/periodic_job.rb | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename config/initializers/{solr.rb => enable_solr.rb} (100%) diff --git a/config/initializers/solr.rb b/config/initializers/enable_solr.rb similarity index 100% rename from config/initializers/solr.rb rename to config/initializers/enable_solr.rb diff --git a/config/initializers/periodic_job.rb b/config/initializers/periodic_job.rb index 55c5dd9d2c..a83401a271 100644 --- a/config/initializers/periodic_job.rb +++ b/config/initializers/periodic_job.rb @@ -10,7 +10,7 @@ Rails.logger.info('Setting up PeriodicJobs') jobs = %w[ArchiveBulkExports RecalculateAge] -jobs << OptimizeSolr.to_s if Rails.application.config.solr_enabled +jobs << OptimizeSolr.to_s if Rails.configuration.solr_enabled jobs.each do |job_name| next if Delayed::Job.where('handler LIKE :job_class', job_class: "%job_class: #{job_name}%").exists? From 9c4d8b341f00a8dece015548ecf9e1e79c1c2331 Mon Sep 17 00:00:00 2001 From: Dennis Hernandez Date: Tue, 15 Oct 2024 22:57:40 -0600 Subject: [PATCH 2/2] Fix script to generate searchable_identifiers The method generate_searchable_identifiers was restored and the script now can tell exactly how many identifiers will be created. --- app/models/concerns/phonetic_searchable.rb | 14 +++++++------ .../v2.11/calculate_searchable_identifiers.rb | 21 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/models/concerns/phonetic_searchable.rb b/app/models/concerns/phonetic_searchable.rb index f171992623..b8a392856b 100644 --- a/app/models/concerns/phonetic_searchable.rb +++ b/app/models/concerns/phonetic_searchable.rb @@ -32,11 +32,15 @@ def recalculate_phonetic_tokens end def recalculate_searchable_identifiers - return unless filterable_id_fields_to_save.present? + return unless filterable_id_fields_changed? + generate_searchable_identifiers + end + + def generate_searchable_identifiers identifiers_to_save = identifiers_to_update - filterable_id_fields_to_save.each do |field_name| + self.class.filterable_id_fields.each do |field_name| next if data[field_name].blank? || identifiers_to_save.any? { |identifier| identifier[:field_name] == field_name } identifiers_to_save << { field_name:, value: data[field_name] } @@ -46,8 +50,6 @@ def recalculate_searchable_identifiers end def identifiers_to_update - return [] unless filterable_id_fields_to_save.present? - searchable_identifiers.map do |searchable_identifier| { field_name: searchable_identifier.field_name, @@ -57,8 +59,8 @@ def identifiers_to_update end end - def filterable_id_fields_to_save - changes_to_save_for_record.keys & self.class.filterable_id_fields + def filterable_id_fields_changed? + (changes_to_save_for_record.keys & self.class.filterable_id_fields).present? end def generate_tokens diff --git a/db/data_migration/v2.11/calculate_searchable_identifiers.rb b/db/data_migration/v2.11/calculate_searchable_identifiers.rb index b0ef0d0b83..58a0c59b82 100644 --- a/db/data_migration/v2.11/calculate_searchable_identifiers.rb +++ b/db/data_migration/v2.11/calculate_searchable_identifiers.rb @@ -6,7 +6,7 @@ # rails r bin/calculate_solr_fields Child,Incident,TracingRequest true file/path.txt def print_log(message) - message = "[#{DateTime.now.strftime('%m/%d/%Y %H:%M')}]: #{message}" + message = "[#{DateTime.now.strftime('%m/%d/%Y %H:%M:%S')}]: #{message}" puts message end @@ -28,17 +28,18 @@ def records_to_process(model_class, ids_file_path) records_to_process(model, file_path).find_in_batches(batch_size: 1000).with_index do |records, batch| print_log("Process #{model.name} batch #{batch}...") records.each do |record| + current_size = record.searchable_identifiers.size + record.generate_searchable_identifiers + generated_size = record.searchable_identifiers.size + total = generated_size - current_size + record_info = "record_type: #{model.name}, record_id: #{record.id}" + field_names = record.searchable_identifiers.map(&:field_name) + identifiers_info = "Searchable Identifiers[#{field_names.join(', ')}]" if save_records - current_size = record.searchable_identifiers.size - record.generate_searchable_identifiers - generated_size = record.searchable_identifiers.size - total = generated_size - current_size - print_log("#{total} Searchable Identifiers generated for record_type: #{model.name}, record_id: #{record.id}") - elsif record.searchable_identifiers.present? - identifiers_size = record.searchable_identifiers.size - print_log("record_type: #{model.name}, record_id: #{record.id} has #{identifiers_size} Searchable Identifiers") + record.save! + print_log("#{total} - #{identifiers_info} generated for #{record_info}") else - print_log("record_type: #{model.name}, record_id: #{record.id} does not have Searchable Identifiers") + print_log("#{total} - #{identifiers_info} will be generated for #{record_info}") end end end