<commit_before>class Tip < ActiveRecord::Base
  belongs_to :product
  belongs_to :from, class_name: 'User'
  belongs_to :to,   class_name: 'User'
  belongs_to :via,  touch: true, polymorphic: true
  has_one :deeds, as: :karma_event

  def self.perform!(product, from, via, add_cents)
    to = via.tip_receiver
    created_at = Time.now

    tip = Tip.find_or_initialize_by(product: product, from: from, to: to, via: via)
    tip.cents ||= 0

    tip.with_lock do
      TransactionLogEntry.transfer!(product, from.id, to.id, add_cents, via.id, created_at)

      tip.cents += add_cents
      tip.save!
    end

    karma_value = 1
    if not to.nil?
      chronicle_id = Chronicle.where(user_id: to.id)
    else
      chronicle = Chronicle.create(user_id: to.id)
      chronicle_id = chronicle.id
    end

    Deed.create!({karma_value: karma_value, karma_event: tip, user_id: to.id, chronicle_id: chronicle_id})


    tip
  end
end<commit_msg>fixed small typo with where/findby<commit_after>class Tip < ActiveRecord::Base
  belongs_to :product
  belongs_to :from, class_name: 'User'
  belongs_to :to,   class_name: 'User'
  belongs_to :via,  touch: true, polymorphic: true
  has_one :deeds, as: :karma_event

  def self.perform!(product, from, via, add_cents)
    to = via.tip_receiver
    created_at = Time.now

    tip = Tip.find_or_initialize_by(product: product, from: from, to: to, via: via)
    tip.cents ||= 0

    tip.with_lock do
      TransactionLogEntry.transfer!(product, from.id, to.id, add_cents, via.id, created_at)

      tip.cents += add_cents
      tip.save!
    end

    karma_value = 1
    if not to.nil?
      chronicle_id = Chronicle.find_by(user_id: to.id).id
    else
      chronicle = Chronicle.create(user_id: to.id)
      chronicle_id = chronicle.id
    end

    Deed.create!({karma_value: karma_value, karma_event: tip, user_id: to.id, chronicle_id: chronicle_id})


    tip
  end
end
{'fraction_non_alphanumeric': 0.10669456066945607, 'fraction_numerical': 0.0020920502092050207, 'mean_word_length': 3.298876404494382, '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': '6913206', 'n_tokens_mistral': 722, 'n_tokens_neox': 689, 'n_words': 165}