<commit_before>class Post < ApplicationRecord
  include RailsSettings::Extend

  belongs_to :user
  has_many :post_bands, dependent: :destroy
  has_many :bands, through: :post_bands

  mount_uploader :thumbnail, PostThumbUploader

  validates :url, presence: true, uniqueness: true

  after_create :scrap_url, if: proc { |p| p.url.present? }

  scope :newest_first, -> { order(created_at: :desc) }

  private

  def scrap_url
    ScrapPostUrlWorker.perform_async(id)<commit_msg>Move post scrapping to after_commit<commit_after>class Post < ApplicationRecord
  include RailsSettings::Extend

  belongs_to :user
  has_many :post_bands, dependent: :destroy
  has_many :bands, through: :post_bands

  mount_uploader :thumbnail, PostThumbUploader

  validates :url, presence: true, uniqueness: true

  after_commit :scrap_url, on: :create, if: proc { |p| p.url.present? }

  scope :newest_first, -> { order(created_at: :desc) }

  private

  def scrap_url
    ScrapPostUrlWorker.perform_async(id)
{'fraction_non_alphanumeric': 0.09384460141271443, 'fraction_numerical': 0.0, 'mean_word_length': 5.085889570552148, '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': '2802472', 'n_tokens_mistral': 339, 'n_tokens_neox': 321, 'n_words': 81}