Files
redux-scraper/app/jobs/domain/fa/job/scan_post_utils.rb
2025-01-01 03:29:53 +00:00

19 lines
563 B
Ruby

# typed: true
module Domain::Fa::Job
class ScanPostUtils
def self.find_or_create_by_fa_ids(fa_ids, caused_by_entry: nil)
posts = Domain::Fa::Post.where(fa_id: fa_ids).to_a
missing = fa_ids - posts.map(&:fa_id)
missing.each do |fa_id|
post = Domain::Fa::Post.create!(fa_id: fa_id)
Domain::Fa::Job::ScanPostJob.perform_later(
{ post: post, caused_by_entry: caused_by_entry }
)
posts << post
end
posts = posts.index_by(&:fa_id)
fa_ids.map { |fa_id| posts[fa_id] }
end
end
end