19 lines
563 B
Ruby
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
|