<commit_before>class DuplicateBikeFinderWorker
  include Sidekiq::Worker
  sidekiq_options queue: 'afterwards', backtrace: true, :retry => false

  def perform(bike_id)
    serial_segments = Bike.find(bike_id).normalized_serial_segments

    serial_segments.each do |serial_segment|
      existing_duplicate = DuplicateBikeGroup.includes(:normalized_serial_segments).
        where(normalized_serial_segments: { segment: serial_segment.segment }).first
      if existing_duplicate.present?
        serial_segment.update_attribute :duplicate_bike_group_id, existing_duplicate.id 
        existing_duplicate.update_attribute :added_bike_at, Time.now
      else
        duplicate_segments = NormalizedSerialSegment.where(segment: serial_segment.segment)
        if duplicate_segments.count > 1
          duplicate_group = DuplicateBikeGroup.create
          duplicate_segments.each do |duplicate_segment|
            next if duplicate_segment.duplicate_bike_group_id.present?
            duplicate_segment.update_attribute :duplicate_bike_group_id, duplicate_group.id
          end
        end
      end
    end

  end

end<commit_msg>remove duplicate bike groups if they aren't around after<commit_after>class DuplicateBikeFinderWorker
  include Sidekiq::Worker
  sidekiq_options queue: 'afterwards', backtrace: true, :retry => false

  def perform(bike_id)
    serial_segments = Bike.find(bike_id).normalized_serial_segments

    serial_segments.each do |serial_segment|
      existing_duplicate = DuplicateBikeGroup.includes(:normalized_serial_segments).
        where(normalized_serial_segments: { segment: serial_segment.segment }).first
      if existing_duplicate.present?
        serial_segment.update_attribute :duplicate_bike_group_id, existing_duplicate.id 
        existing_duplicate.update_attribute :added_bike_at, Time.now
      else
        duplicate_segments = NormalizedSerialSegment.where(segment: serial_segment.segment)
        if duplicate_segments.count > 1
          duplicate_group = DuplicateBikeGroup.create
          duplicate_segments.each do |duplicate_segment|
            next if duplicate_segment.duplicate_bike_group_id.present?
            duplicate_segment.update_attribute :duplicate_bike_group_id, duplicate_group.id
          end
          duplicate_group.destroy if duplicate_group.normalized_serial_segments.empty?
        end
      end
    end


  end

end
{'fraction_non_alphanumeric': 0.05887265135699374, 'fraction_numerical': 0.0008350730688935282, 'mean_word_length': 3.8502024291497974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1777927', 'n_tokens_mistral': 688, 'n_tokens_neox': 688, 'n_words': 122}