<commit_before>class PathReservation < ActiveRecord::Base
  validates :base_path, absolute_path: true
  validates :publishing_app, presence: true
  validates_with PublishingAppValidator

  def self.reserve_base_path!(base_path, publishing_app)
    record = find_or_initialize_by(base_path: base_path)
    record.publishing_app = publishing_app
    record.save!
  rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation
    # If a path is already reserved by the same publishing app, ignore the error
    record = find_by(base_path: base_path)
    raise unless record.publishing_app == publishing_app

    record
  end
end<commit_msg>Wrap saving base path reservation in a transaction<commit_after>class PathReservation < ActiveRecord::Base
  validates :base_path, absolute_path: true
  validates :publishing_app, presence: true
  validates_with PublishingAppValidator

  def self.reserve_base_path!(base_path, publishing_app)
    record = find_or_initialize_by(base_path: base_path)
    ActiveRecord::Base.transaction do
      record.update!(publishing_app: publishing_app)
    end
  rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation
    # If a path is already reserved by the same publishing app, ignore the error
    record = find_by(base_path: base_path)
    raise unless record.publishing_app == publishing_app

    record
  end
end
{'fraction_non_alphanumeric': 0.06092124814264487, 'fraction_numerical': 0.0, 'mean_word_length': 5.265116279069767, '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': '6319373', 'n_tokens_mistral': 386, 'n_tokens_neox': 384, 'n_words': 106}