<commit_before>require 'identity/importer/tasks/opens'

module Identity
  module Importer
    module Tasks
      module CiviCRM
        class Opens < Identity::Importer::Tasks::Opens

          def self.sql(mailing_id, last_open)
            anonymize = Identity::Importer.configuration.anonymize
            %{
              SELECT
                #{anonymize ? "concat(sha1(email.email), '@civi.crm')" : "email.email"} as email,
                open.time_stamp as timestamp
                FROM civicrm_mailing m JOIN civicrm_mailing_job job ON m.id = job.mailing_id
                JOIN civicrm_mailing_event_queue eventqueue ON eventqueue.job_id = job.id
                JOIN civicrm_email email ON eventqueue.email_id = email.id
                LEFT JOIN civicrm_mailing_event_opened open ON open.event_queue_id = eventqueue.id
                WHERE job.job_type = 'child'
                AND m.id = #{mailing_id}
                AND open.time_stamp is not null
                AND open.time_stamp > #{ActiveRecord::Base.connection.quote(last_open)}
                ORDER BY eventqueue.id ASC
            }
          end

        end
      end
    end
  end
end<commit_msg>fix: import only first open<commit_after>require 'identity/importer/tasks/opens'

module Identity
  module Importer
    module Tasks
      module CiviCRM
        class Opens < Identity::Importer::Tasks::Opens

          def self.sql(mailing_id, last_open)
            anonymize = Identity::Importer.configuration.anonymize
            %{
              SELECT
                #{anonymize ? "concat(sha1(email.email), '@civi.crm')" : "email.email"} as email,
                min(open.time_stamp) as timestamp
                FROM civicrm_mailing m JOIN civicrm_mailing_job job ON m.id = job.mailing_id
                JOIN civicrm_mailing_event_queue eventqueue ON eventqueue.job_id = job.id
                JOIN civicrm_email email ON eventqueue.email_id = email.id
                LEFT JOIN civicrm_mailing_event_opened open ON open.event_queue_id = eventqueue.id
                WHERE job.job_type = 'child'
                AND m.id = #{mailing_id}
                AND open.time_stamp is not null
                AND open.time_stamp > #{ActiveRecord::Base.connection.quote(last_open)}
                GROUP BY email.email
                ORDER BY eventqueue.id ASC
            }
          end

        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07048092868988391, 'fraction_numerical': 0.0008291873963515755, 'mean_word_length': 1.8829151732377538, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1551423', 'n_tokens_mistral': 729, 'n_tokens_neox': 677, 'n_words': 166}