load all fa ids
This commit is contained in:
@@ -28,50 +28,37 @@ class Tasks::Fa::QueryMissingPostsFromFuzzysearch < EnqueueJobBase
|
||||
query =
|
||||
query.where(fa_id: ..greatest_ok_post_fa_id) if greatest_ok_post_fa_id
|
||||
query = query.where(fa_id: ..@start_at) if @start_at
|
||||
query = query.where.missing(:file).order(fa_id: :desc)
|
||||
|
||||
log("finding greatest qualifying fa_id...")
|
||||
greatest_post_fa_id = query.first&.fa_id
|
||||
|
||||
log("counting posts...")
|
||||
count = GlobalState.get(COUNT_KEY)&.to_i || query.count
|
||||
GlobalState.set(COUNT_KEY, count.to_s)
|
||||
log("loading fa_ids...")
|
||||
fa_ids = query.where.missing(:file).order(fa_id: :desc).pluck(:fa_id).uniq
|
||||
count = fa_ids.count
|
||||
|
||||
puts "number of posts to process: #{count}"
|
||||
pb = create_progress_bar(count)
|
||||
|
||||
while greatest_post_fa_id
|
||||
posts = query.where(fa_id: ..greatest_post_fa_id).limit(32).to_a
|
||||
break if posts.empty?
|
||||
|
||||
posts.each do |post|
|
||||
fa_ids.each_slice(32) do |fa_ids_slice|
|
||||
fa_ids_slice.each do |fa_id|
|
||||
break if interrupted?
|
||||
|
||||
enqueue do
|
||||
Domain::Fa::Job::ScanFuzzysearchJob.perform_later(
|
||||
{ fa_id: post.fa_id },
|
||||
)
|
||||
Domain::Fa::Job::ScanFuzzysearchJob.perform_later({ fa_id: fa_id })
|
||||
end
|
||||
|
||||
post_desc =
|
||||
"#{(post.creator&.to_param || "(none)").rjust(20)} / #{post.to_param}".ljust(
|
||||
40,
|
||||
)
|
||||
log("migrate post :: #{post_desc}") if pb.progress % 10 == 0
|
||||
if pb.progress % 10 == 0
|
||||
post = Domain::Post::FaPost.find_by!(fa_id: fa_id)
|
||||
post_desc =
|
||||
"#{(post.creator&.to_param || "(none)").rjust(20)} / #{post.to_param}".ljust(
|
||||
40,
|
||||
)
|
||||
log("migrate post :: #{post_desc}")
|
||||
end
|
||||
rescue StandardError
|
||||
log("error processing post :: #{post_desc}")
|
||||
log("error processing post :: #{fa_id}")
|
||||
ensure
|
||||
pb.progress = [pb.progress + 1, pb.total].min
|
||||
end
|
||||
|
||||
last_processed_fa_id = posts.map(&:fa_id).compact.min
|
||||
if last_processed_fa_id
|
||||
save_progress(last_processed_fa_id.to_s)
|
||||
GlobalState.set(COUNT_KEY, (count - pb.progress).to_s)
|
||||
greatest_post_fa_id = last_processed_fa_id - 1
|
||||
else
|
||||
break
|
||||
end
|
||||
save_progress(fa_ids_slice.last.to_s)
|
||||
|
||||
# Check for interruption after processing batch
|
||||
break if interrupted?
|
||||
|
||||
Reference in New Issue
Block a user