<commit_before>class Connection < ApplicationRecord
  belongs_to :developer, touch: true
  validates_presence_of :uid, :provider, :access_token
  validates_uniqueness_of :uid, scope: :provider

  def self.find_or_create_for_oauth(auth)
    @connection ||= find_for_oauth(auth)
    @connection.nil? ? create_from_oauth(auth) : @connection
  end

  def self.find_for_oauth(auth)
    where(uid: auth.uid, provider: auth.provider).first
  end

  def self.create_from_oauth(auth)
   create!(
      uid: auth.uid,
      provider: auth.provider,
      access_token: auth.credentials.token,
    )
  end
end<commit_msg>Wrap the creation in a transaction block<commit_after>class Connection < ApplicationRecord
  belongs_to :developer, touch: true
  validates_presence_of :uid, :provider, :access_token
  validates_uniqueness_of :uid, scope: :provider

  def self.find_or_create_for_oauth(auth)
    ActiveRecord::Base.transaction do
      @connection ||= find_for_oauth(auth)
      @connection.nil? ? create_from_oauth(auth) : @connection
    end
  end

  def self.find_for_oauth(auth)
    where(uid: auth.uid, provider: auth.provider).first
  end

  def self.create_from_oauth(auth)
   create!(
      uid: auth.uid,
      provider: auth.provider,
      access_token: auth.credentials.token,
    )
  end
end
{'fraction_non_alphanumeric': 0.09483423284502698, 'fraction_numerical': 0.0, 'mean_word_length': 4.171314741035856, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4003977', 'n_tokens_mistral': 437, 'n_tokens_neox': 430, 'n_words': 90}