better progress bar, new thumbnails/fingerprints bust cache

This commit is contained in:
Dylan Knutson
2025-06-26 07:02:53 +00:00
parent c20e7a0b7e
commit e3b2463cbe
5 changed files with 51 additions and 22 deletions

View File

@@ -292,28 +292,31 @@ task run_fa_user_avatar_jobs: :environment do
end
end
task create_post_file_fingerprints: :environment do
task create_post_file_fingerprints: %i[environment set_logger_stdout] do
def migrate_posts_for_user(user)
puts "migrating posts for #{user.to_param}"
posts = user.posts.includes(files: %i[blob thumbnails bit_fingerprints])
pb =
ProgressBar.create(
total: user.posts.count,
format: "%t: %c/%C %B %p%% %a %e",
total: posts.count,
progress_mark: " ",
remainder_mark: " ",
format: "%B %c/%C (%r/sec) %J%% %a %E",
)
user
.posts
.includes(:files)
.find_in_batches(batch_size: 64) do |batch|
ReduxApplicationRecord.transaction do
batch.each { |post| migrate_post(post) }
posts.find_in_batches(batch_size: 64) do |batch|
ReduxApplicationRecord.transaction do
batch.each do |post|
migrate_post(post)
pb.progress = [pb.progress + 1, pb.total].min
end
end
end
end
def migrate_post(post)
puts "migrating #{post.id} / #{post.to_param} / '#{post.title_for_view}'"
puts "#{post.creator&.url_name} (#{post.creator&.user_user_follows_to_count}) :: #{post.to_param} / '#{post.title_for_view}'"
ColorLogger.quiet do
post.files.each do |file|
migrate_post_file(file)
@@ -324,9 +327,8 @@ task create_post_file_fingerprints: :environment do
end
def migrate_post_file(post_file)
job = Domain::PostFileThumbnailJob.new
ColorLogger.quiet do
job.perform({ post_file: })
Domain::PostFileThumbnailJob.new.perform({ post_file: })
rescue => e
puts "error: #{e.message}"
end
@@ -334,7 +336,13 @@ task create_post_file_fingerprints: :environment do
if ENV["post_file_descending"].present?
total = 49_783_962 # cache this value
pb = ProgressBar.create(total:, format: "%t: %c/%C %B %p%% %a %e")
pb =
ProgressBar.create(
total:,
progress_mark: " ",
remainder_mark: " ",
format: "%B %c/%C (%r/sec) %J%% %a %E",
)
i = 0
Domain::PostFile
.where(state: "ok")
@@ -354,7 +362,13 @@ task create_post_file_fingerprints: :environment do
elsif ENV["posts_descending"].present?
# total = Domain::Post.count
total = 66_431_808 # cache this value
pb = ProgressBar.create(total:, format: "%t: %c/%C %B %p%% %a %e")
pb =
ProgressBar.create(
total:,
progress_mark: " ",
remainder_mark: " ",
format: "%B %c/%C (%r/sec) %J%% %a %E",
)
Domain::Post.find_each(order: :desc) do |post|
migrate_post(post) unless post.is_a?(Domain::Post::InkbunnyPost)
pb.progress = [pb.progress + 1, pb.total].min
@@ -371,7 +385,7 @@ task create_post_file_fingerprints: :environment do
migrated_users = migrated_file.readlines.map(&:strip)
users =
Domain::User::FaUser.order(
Arel.sql("json_attributes->>'num_watched_by' DESC NULLS LAST"),
Arel.sql("user_user_follows_to_count DESC NULLS LAST"),
).pluck(:id)
users.each do |user_id|

View File

@@ -16,7 +16,10 @@ class Domain::Fa::EnqueueDueUserPageScans < EnqueueJobBase
.to_a
if users.empty? ||
((sfa = users.first&.scanned_page_at) && sfa > 89.days.ago)
(
(sfa = users.map(&:scanned_page_at).compact.max) &&
sfa > 89.days.ago
)
break
end

View File

@@ -53,7 +53,6 @@ class Domain::Fa::EnqueueUnscannedOkPosts < EnqueueJobBase
ReduxApplicationRecord.transaction do
posts.each do |post|
# print "#{processed.to_s.rjust(ljust_by)} / #{total}: "
process_post(post, hle_map)
processed += 1
pb.progress = [processed, pb.total].min
@@ -71,21 +70,32 @@ class Domain::Fa::EnqueueUnscannedOkPosts < EnqueueJobBase
def process_post(post, hle_map)
fa_id = T.must(post.fa_id)
if hle = (hle_map[fa_id] || post.guess_last_submission_log_entry)
binding.pry unless post.external_url_for_view == hle.uri
unless post.external_url_for_view.to_s.delete_suffix("/") ==
hle.uri.to_s.delete_suffix("/")
puts "uri mismatch: #{post.external_url_for_view} != #{hle.uri}"
puts "post: #{post_id_str(post)}"
puts "hle: #{hle.uri_host} #{hle.uri_path} #{hle.requested_at}"
raise("uri mismatch")
end
puts "existing log entry for #{post.to_param} / #{post.title_for_view} / #{post.creator&.to_param}"
puts "existing log entry for #{post_id_str(post)}"
post.scanned_at = hle.requested_at
post.last_submission_log_entry = hle
post.posted_at = post.posted_at if post.attributes["posted_at"].nil?
post.save!
else
enqueue do
puts "enqueued #{post.to_param} / #{post.title_for_view} / #{post.creator&.to_param}"
puts "enqueued #{post_id_str(post)}"
Domain::Fa::Job::ScanPostJob.perform_later({ post: })
end
end
end
sig { params(post: Domain::Post::FaPost).returns(String) }
def post_id_str(post)
"#{post.to_param} / #{post.title_for_view} / #{post.creator&.to_param}"
end
sig { override.returns(Integer) }
def queue_size
count_failed_in_queue("fa_post")

View File

@@ -5,7 +5,8 @@ class Domain::PostFile::BitFingerprint < ReduxApplicationRecord
belongs_to :post_file,
class_name: "::Domain::PostFile",
inverse_of: :bit_fingerprints
inverse_of: :bit_fingerprints,
touch: true
belongs_to :thumbnail, class_name: "::Domain::PostFile::Thumbnail"

View File

@@ -5,7 +5,8 @@ class Domain::PostFile::Thumbnail < ReduxApplicationRecord
belongs_to :post_file,
class_name: "::Domain::PostFile",
inverse_of: :thumbnails
inverse_of: :thumbnails,
touch: true
enum :thumb_type, { content_container: 0, size_32_32: 1 }
validates :thumb_type, presence: true