<commit_before>module CurationConcerns
  module Actors
    class ApplyOrderActor < AbstractActor
      def update(attributes)
        ordered_member_ids = attributes.delete(:ordered_member_ids)
        sync_members(ordered_member_ids)
        apply_order(ordered_member_ids) && next_actor.update(attributes)
      end

      private

        def sync_members(ordered_member_ids)
          return true if ordered_member_ids.nil?
          existing_members_ids = curation_concern.member_ids
          (existing_members_ids - ordered_member_ids).each do |old_id|
            work = ::ActiveFedora::Base.find(old_id)
            curation_concern.ordered_members.delete(work)
          end

          (ordered_member_ids - existing_members_ids).each do |work_id|
            work = ::ActiveFedora::Base.find(work_id)
            curation_concern.ordered_members << work
          end
          true
        end

        def apply_order(new_order)
          return true unless new_order
          curation_concern.ordered_member_proxies.each_with_index do |proxy, index|
            unless new_order[index]
              proxy.prev.next = curation_concern.ordered_member_proxies.last.next
              break
            end
            proxy.proxy_for = ActiveFedora::Base.id_to_uri(new_order[index])
            proxy.target = nil
          end<commit_msg>Use ordered member ids instead of ids<commit_after>module CurationConcerns
  module Actors
    class ApplyOrderActor < AbstractActor
      def update(attributes)
        ordered_member_ids = attributes.delete(:ordered_member_ids)
        sync_members(ordered_member_ids)
        apply_order(ordered_member_ids) && next_actor.update(attributes)
      end

      private

        def sync_members(ordered_member_ids)
          return true if ordered_member_ids.nil?
          existing_members_ids = curation_concern.ordered_member_ids
          (existing_members_ids - ordered_member_ids).each do |old_id|
            work = ::ActiveFedora::Base.find(old_id)
            curation_concern.ordered_members.delete(work)
          end

          (ordered_member_ids - existing_members_ids).each do |work_id|
            work = ::ActiveFedora::Base.find(work_id)
            curation_concern.ordered_members << work
          end
          true
        end

        def apply_order(new_order)
          return true unless new_order
          curation_concern.ordered_member_proxies.each_with_index do |proxy, index|
            unless new_order[index]
              proxy.prev.next = curation_concern.ordered_member_proxies.last.next
              break
            end
            proxy.proxy_for = ActiveFedora::Base.id_to_uri(new_order[index])
            proxy.target = nil
          end
{'fraction_non_alphanumeric': 0.06359649122807018, 'fraction_numerical': 0.0, 'mean_word_length': 2.4084682440846823, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '252897', 'n_tokens_mistral': 777, 'n_tokens_neox': 760, 'n_words': 133}