@@ -16,7 +16,7 @@ def call
1616 valid_areas = filter_and_prepare_areas
1717
1818 if valid_areas . empty?
19- Rails . logger . info " Areas import completed. Created: 0"
19+ Rails . logger . info ' Areas import completed. Created: 0'
2020 return 0
2121 end
2222
@@ -53,9 +53,7 @@ def filter_and_prepare_areas
5353 valid_areas << prepared_attributes if prepared_attributes
5454 end
5555
56- if skipped_count > 0
57- Rails . logger . warn "Skipped #{ skipped_count } areas with invalid or missing required data"
58- end
56+ Rails . logger . warn "Skipped #{ skipped_count } areas with invalid or missing required data" if skipped_count > 0
5957
6058 valid_areas
6159 end
@@ -84,7 +82,7 @@ def filter_existing_areas(areas)
8482 existing_areas_lookup [ key ] = true
8583 end
8684
87- filtered_areas = areas . reject do |area |
85+ areas . reject do |area |
8886 key = [ area [ :name ] , area [ :latitude ] . to_f , area [ :longitude ] . to_f ]
8987 if existing_areas_lookup [ key ]
9088 Rails . logger . debug "Area already exists: #{ area [ :name ] } "
@@ -93,31 +91,28 @@ def filter_existing_areas(areas)
9391 false
9492 end
9593 end
96-
97- filtered_areas
9894 end
9995
10096 def bulk_import_areas ( areas )
10197 total_created = 0
10298
10399 areas . each_slice ( BATCH_SIZE ) do |batch |
104- begin
105- result = Area . upsert_all (
106- batch ,
107- returning : %w[ id ] ,
108- on_duplicate : :skip
109- )
110-
111- batch_created = result . count
112- total_created += batch_created
113-
114- Rails . logger . debug "Processed batch of #{ batch . size } areas, created #{ batch_created } , total created: #{ total_created } "
115-
116- rescue StandardError => e
117- Rails . logger . error "Failed to process area batch: #{ e . message } "
118- Rails . logger . error "Batch size: #{ batch . size } "
119- Rails . logger . error "Backtrace: #{ e . backtrace . first ( 3 ) . join ( '\n' ) } "
120- end
100+ # rubocop:disable Rails/SkipsModelValidations
101+ result = Area . upsert_all (
102+ batch ,
103+ returning : %w[ id ] ,
104+ on_duplicate : :skip
105+ )
106+ # rubocop:enable Rails/SkipsModelValidations
107+
108+ batch_created = result . count
109+ total_created += batch_created
110+
111+ Rails . logger . debug "Processed batch of #{ batch . size } areas, created #{ batch_created } , total created: #{ total_created } "
112+ rescue StandardError => e
113+ Rails . logger . error "Failed to process area batch: #{ e . message } "
114+ Rails . logger . error "Batch size: #{ batch . size } "
115+ Rails . logger . error "Backtrace: #{ e . backtrace . first ( 3 ) . join ( '\n' ) } "
121116 end
122117
123118 total_created
0 commit comments