<commit_before>class TicketSearch < ApplicationRecord
  belongs_to(:ticket)

  def self.new(lottery_id:, query:)
    query = query.to_s
    where_attributes = { lottery_id: lottery_id }

    ticket_ids = if query.to_i > 0
      where_attributes[:number] = query
    elsif query.present?
      ticket_ids = TicketSearch.fuzzy_search(query).map(&:ticket_id)
      where_attributes[:id] = ticket_ids
    end

    Ticket.where(where_attributes)
  end

  private

  def readonly?
    true
  end
end<commit_msg>remove n+1 when fetching all tickets_controller#index<commit_after>class TicketSearch < ApplicationRecord
  belongs_to(:ticket)

  def self.new(lottery_id:, query:)
    query = query.to_s
    where_attributes = { lottery_id: lottery_id }

    ticket_ids = if query.to_i > 0
      where_attributes[:number] = query
    elsif query.present?
      ticket_ids = TicketSearch.fuzzy_search(query).map(&:ticket_id)
      where_attributes[:id] = ticket_ids
    end

    Ticket.includes(:seller, :guest, :sponsor, :table).where(where_attributes)
  end

  private

  def readonly?
    true
  end
end
{'fraction_non_alphanumeric': 0.09323583180987204, 'fraction_numerical': 0.002742230347349177, 'mean_word_length': 3.6794871794871793, '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': '6244937', 'n_tokens_mistral': 380, 'n_tokens_neox': 356, 'n_words': 73}