@@ -199,19 +199,19 @@ def merge_instructeur_buffer_stream!
199199 end
200200
201201 def reset_user_buffer_stream!
202- champs . where ( stream : Champ ::USER_BUFFER_STREAM ) . destroy_all
202+ champ_data . where ( stream : Champ ::USER_BUFFER_STREAM ) . destroy_all
203203
204204 # update loaded champ instances
205- association ( :champs ) . target = champs . filter { _1 . stream != Champ ::USER_BUFFER_STREAM }
205+ association ( :champ_data ) . target = champ_data . filter { _1 . stream != Champ ::USER_BUFFER_STREAM }
206206
207207 reset_champs_cache
208208 end
209209
210210 def reset_instructeur_buffer_stream!
211- champs . where ( stream : Champ ::INSTRUCTEUR_BUFFER_STREAM ) . destroy_all
211+ champ_data . where ( stream : Champ ::INSTRUCTEUR_BUFFER_STREAM ) . destroy_all
212212
213213 # update loaded champ instances
214- association ( :champs ) . target = champs . filter { _1 . stream != Champ ::INSTRUCTEUR_BUFFER_STREAM }
214+ association ( :champ_data ) . target = champ_data . filter { _1 . stream != Champ ::INSTRUCTEUR_BUFFER_STREAM }
215215
216216 reset_champs_cache
217217 end
@@ -268,7 +268,7 @@ def stream
268268 end
269269
270270 def history
271- champs . filter ( &:history_stream? )
271+ champ_data . filter ( &:history_stream? )
272272 end
273273
274274 def set_default_value_for_france_connect_champs ( user_email )
@@ -302,13 +302,13 @@ def instructeur_changed_columns
302302 private
303303
304304 def changed_champ_ids_for_merge ( stream )
305- stream_h = champs . where ( stream :, stable_id : revision_stable_ids )
305+ stream_h = champ_data . where ( stream :, stable_id : revision_stable_ids )
306306 . pluck ( :stable_id , :row_id , :id )
307307 . to_h { |( stable_id , row_id , id ) | [ TypeDeChamp . public_id ( stable_id , row_id ) , id ] }
308308
309309 return [ [ ] , [ ] ] if stream_h . empty?
310310
311- main_h = champs . where ( stream : Champ ::MAIN_STREAM , stable_id : revision_stable_ids )
311+ main_h = champ_data . where ( stream : Champ ::MAIN_STREAM , stable_id : revision_stable_ids )
312312 . pluck ( :stable_id , :row_id , :id )
313313 . to_h { |( stable_id , row_id , id ) | [ TypeDeChamp . public_id ( stable_id , row_id ) , id ] }
314314
@@ -318,14 +318,14 @@ def changed_champ_ids_for_merge(stream)
318318 changed_ids = main_public_ids . intersection ( stream_public_ids ) . map { main_h [ it ] }
319319 stream_ids = stream_h . values
320320
321- # mark champs in discarded rows as changed
322- discarded_row_ids = champs . where ( stream :, stable_id : revision_stable_ids )
321+ # mark champ_data in discarded rows as changed
322+ discarded_row_ids = champ_data . where ( stream :, stable_id : revision_stable_ids )
323323 . where . not ( row_id : nil )
324324 . where . not ( discarded_at : nil )
325325 . pluck ( :row_id )
326326
327327 if discarded_row_ids . present?
328- changed_ids += champs . where ( stream : Champ ::MAIN_STREAM , row_id : discarded_row_ids ) . pluck ( :id )
328+ changed_ids += champ_data . where ( stream : Champ ::MAIN_STREAM , row_id : discarded_row_ids ) . pluck ( :id )
329329 end
330330
331331 [ stream_ids , changed_ids ]
@@ -334,25 +334,25 @@ def changed_champ_ids_for_merge(stream)
334334 def merge_buffer_champs ( buffer_ids , changed_ids , stream )
335335 now = Time . zone . now
336336 history_stream = "#{ Champ ::HISTORY_STREAM } #{ now } "
337- buffer_champs = champs . filter { buffer_ids . member? ( it . id ) }
337+ buffer_champs = champ_data . filter { buffer_ids . member? ( it . id ) }
338338
339339 transaction do
340340 # if merging user buffer, discard any instructeur made changes
341341 if stream == Champ ::USER_BUFFER_STREAM
342- champs . where ( id : buffer_ids , stream :) . pluck ( :stable_id , :row_id ) . each do |( stable_id , row_id ) |
343- champs . where ( stream : Champ ::INSTRUCTEUR_BUFFER_STREAM , stable_id :, row_id :) . destroy_all
342+ champ_data . where ( id : buffer_ids , stream :) . pluck ( :stable_id , :row_id ) . each do |( stable_id , row_id ) |
343+ champ_data . where ( stream : Champ ::INSTRUCTEUR_BUFFER_STREAM , stable_id :, row_id :) . destroy_all
344344 end
345345 end
346346
347- # move champs with changes from "main" to "history" stream
348- champs . where ( id : changed_ids , stream : Champ ::MAIN_STREAM ) . update_all ( stream : history_stream )
349- # move champs from "buffer" to "main"
350- champs . where ( id : buffer_ids , stream :) . update_all ( stream : Champ ::MAIN_STREAM , updated_at : now , checkpoint : history_stream )
347+ # move champ_data with changes from "main" to "history" stream
348+ champ_data . where ( id : changed_ids , stream : Champ ::MAIN_STREAM ) . update_all ( stream : history_stream )
349+ # move champ_data from "buffer" to "main"
350+ champ_data . where ( id : buffer_ids , stream :) . update_all ( stream : Champ ::MAIN_STREAM , updated_at : now , checkpoint : history_stream )
351351 update_champs_timestamps ( buffer_champs , stream )
352352 end
353353
354354 # update loaded champ instances
355- champs . each do |champ |
355+ champ_data . each do |champ |
356356 if champ . id . in? ( changed_ids )
357357 champ . stream = history_stream
358358 elsif champ . id . in? ( buffer_ids )
@@ -401,7 +401,7 @@ def champs_on_stream
401401 when Champ ::INSTRUCTEUR_BUFFER_STREAM
402402 ( champs_on_instructeur_buffer_stream + champs_on_main_stream ) . uniq ( &:public_id )
403403 when Champ ::USER_HISTORY_STREAM
404- champs
404+ champ_data
405405 # only "main" and "history"
406406 . reject ( &:buffer_stream? )
407407 # only updates made before last submission
@@ -420,11 +420,11 @@ def revision_stable_ids
420420 end
421421
422422 def champs_in_revision
423- champs . filter { stable_id_in_revision? ( _1 . stable_id ) }
423+ champ_data . filter { stable_id_in_revision? ( _1 . stable_id ) }
424424 end
425425
426426 def discarded_champs_on_main_stream
427- champs . filter ( &:main_stream? ) . reject { stable_id_in_revision? ( _1 . stable_id ) }
427+ champ_data . filter ( &:main_stream? ) . reject { stable_id_in_revision? ( _1 . stable_id ) }
428428 end
429429
430430 def champs_on_main_stream
@@ -466,11 +466,11 @@ def champ_upsert_by!(type_de_champ, row_id)
466466 Champ . where ( dossier_id : id , row_id : Champ ::NULL_ROW_ID ) . update_all ( row_id : nil )
467467
468468 # FIXME: Try to find the champ in memory before querying the database
469- champ = champs . find { _1 . stream == stream && _1 . public_id == type_de_champ . public_id ( row_id ) }
469+ champ = champ_data . find { _1 . stream == stream && _1 . public_id == type_de_champ . public_id ( row_id ) }
470470
471471 if champ . nil?
472472 champ = Dossier . no_touching do
473- champs
473+ champ_data
474474 . create_with ( **type_de_champ . params_for_champ , source_stream : stream )
475475 . create_or_find_by! ( stable_id : type_de_champ . stable_id , row_id :, stream :)
476476 end
@@ -481,14 +481,14 @@ def champ_upsert_by!(type_de_champ, row_id)
481481 champ = champ . becomes! ( type_de_champ . champ_class )
482482 champ . assign_attributes ( value : nil , value_json : nil , external_id : nil , data : nil )
483483 elsif stream != Champ ::MAIN_STREAM && champ . previously_new_record?
484- main_stream_champ = champs . find_by ( stable_id : type_de_champ . stable_id , row_id :, stream : Champ ::MAIN_STREAM )
484+ main_stream_champ = champ_data . find_by ( stable_id : type_de_champ . stable_id , row_id :, stream : Champ ::MAIN_STREAM )
485485 champ . clone_value_from ( main_stream_champ ) if main_stream_champ . present?
486486 end
487487
488- # If the champ returned from `create_or_find_by` is not the same as the one already loaded in `dossier.champs `, we need to update the association cache
489- loaded_champ = champs . find { [ _1 . stream , _1 . public_id ] == [ champ . stream , champ . public_id ] }
488+ # If the champ returned from `create_or_find_by` is not the same as the one already loaded in `dossier.champ_data `, we need to update the association cache
489+ loaded_champ = champ_data . find { [ _1 . stream , _1 . public_id ] == [ champ . stream , champ . public_id ] }
490490 if loaded_champ . present? && loaded_champ . object_id != champ . object_id
491- association ( :champs ) . target = champs - [ loaded_champ ] + [ champ ]
491+ association ( :champ_data ) . target = champ_data - [ loaded_champ ] + [ champ ]
492492 end
493493
494494 # If the dossier instance on champ has changed we need to update the association cache
0 commit comments