<commit_before>module Ci
  class Runner < ActiveRecord::Base
    extend Gitlab::Ci::Model
    include Gitlab::SQL::Pattern
    include RedisCacheable
    include ChronicDurationAttribute

    RUNNER_QUEUE_EXPIRY_TIME = 60.minutes
    ONLINE_CONTACT_TIMEOUT = 1.hour
    UPDATE_DB_RUNNER_INFO_EVERY = 40.minutes
    AVAILABLE_SCOPES = %w[specific shared active paused online].freeze
    FORM_EDITABLE = %i[description tag_list active run_untagged locked access_level maximum_timeout_human_readable].freeze

    has_many :builds
    has_many :runner_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
    has_many :projects, through: :runner_projects
    has_many :runner_groups
    has_many :groups, through: :runner_groups

    has_one :last_build, ->() { order('id DESC') }, class_name: 'Ci::Build'

    before_validation :set_default_values

    scope :specific, ->() { where(is_shared: false) }
    scope :shared, ->() { where(is_shared: true) }
    scope :active, ->() { where(active: true) }
    scope :paused, ->() { where(active: false) }
    scope :online, ->() { where('contacted_at > ?', contact_time_deadline) }
    scope :ordered, ->() { order(id: :desc) }

    scope :owned_or_shared, ->(project_id) do
      project_runners = joins(
        %{
          LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id
        }
      ).where(
        %{
          ci_runner_projects.project_id = :project_id
        },
        project_id: project_id
      )

      group_runners = joins(
        %{
          LEFT JOIN ci_runner_groups ON ci_runner_groups.runner_id = ci_runners.id
          LEFT JOIN namespaces ON namespaces.id = ci_runner_groups.group_id
          LEFT JOIN projects group_projects ON group_projects.namespace_id = namespaces.id
        }
      ).where(
        %{
          group_projects.id = :project_id
        },
        project_id: project_id
      )
<commit_msg>use INNER JOIN instead of LEFT JOIN<commit_after>module Ci
  class Runner < ActiveRecord::Base
    extend Gitlab::Ci::Model
    include Gitlab::SQL::Pattern
    include RedisCacheable
    include ChronicDurationAttribute

    RUNNER_QUEUE_EXPIRY_TIME = 60.minutes
    ONLINE_CONTACT_TIMEOUT = 1.hour
    UPDATE_DB_RUNNER_INFO_EVERY = 40.minutes
    AVAILABLE_SCOPES = %w[specific shared active paused online].freeze
    FORM_EDITABLE = %i[description tag_list active run_untagged locked access_level maximum_timeout_human_readable].freeze

    has_many :builds
    has_many :runner_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
    has_many :projects, through: :runner_projects
    has_many :runner_groups
    has_many :groups, through: :runner_groups

    has_one :last_build, ->() { order('id DESC') }, class_name: 'Ci::Build'

    before_validation :set_default_values

    scope :specific, ->() { where(is_shared: false) }
    scope :shared, ->() { where(is_shared: true) }
    scope :active, ->() { where(active: true) }
    scope :paused, ->() { where(active: false) }
    scope :online, ->() { where('contacted_at > ?', contact_time_deadline) }
    scope :ordered, ->() { order(id: :desc) }

    scope :owned_or_shared, ->(project_id) do
      project_runners = joins(:runner_projects).where(ci_runner_projects: { project_id: project_id })

      group_runners = joins(
        %{
          INNER JOIN ci_runner_groups ON ci_runner_groups.runner_id = ci_runners.id
          INNER JOIN namespaces ON namespaces.id = ci_runner_groups.group_id
          INNER JOIN projects group_projects ON group_projects.namespace_id = namespaces.id
        }
      ).where(
        %{
          group_projects.id = :project_id
        },
        project_id: project_id
      )

{'fraction_non_alphanumeric': 0.09876873661670235, 'fraction_numerical': 0.0026766595289079227, 'mean_word_length': 3.2855504587155964, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '319476', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1152, 'n_words': 249}