File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,26 @@ def sort_list(new_list, id_column = :id)
3939 active_sorting_make_changes ( old_list , new_list , changes , id_column )
4040 end
4141
42+ def sort_list_slow ( new_list , id_column = :id )
43+ raise ArgumentError , "Sortable list should not be empty" if new_list . empty?
44+ conditions = { id_column => new_list }
45+ old_list = unscoped . active_sorting_default_scope . where ( conditions )
46+ old_list_ids = old_list . pluck ( id_column )
47+
48+ raise Exceptions ::RecordsNotFound , "Sortable list should be persisted to database with #{ name } Model" if old_list_ids . empty?
49+ raise Exceptions ::InvalidListSize , "Sortable new and old lists should be of the same length" if old_list . count != old_list_ids . count
50+
51+ weight_lists = old_list . map { |speaker | speaker . weight }
52+
53+ new_list . each_with_index do |id , index |
54+ current_record = active_sorting_find_by ( id_column , id )
55+ if current_record . active_sorting_value != weight_lists [ index ]
56+ current_record . active_sorting_value = weight_lists [ index ]
57+ current_record . save!
58+ end
59+ end
60+ end
61+
4262 # Default sorting options
4363 def active_sorting_default_options
4464 {
You can’t perform that action at this time.
0 commit comments