diff --git a/app/lib/tasks/inkbunny.rb b/app/lib/tasks/inkbunny.rb new file mode 100644 index 00000000..f3bda8f4 --- /dev/null +++ b/app/lib/tasks/inkbunny.rb @@ -0,0 +1,5 @@ +# typed: strict +# frozen_string_literal: true + +module Tasks::Inkbunny +end diff --git a/app/lib/tasks/inkbunny/enqueue_missing_posts_task.rb b/app/lib/tasks/inkbunny/enqueue_missing_posts_task.rb new file mode 100644 index 00000000..0f83eef9 --- /dev/null +++ b/app/lib/tasks/inkbunny/enqueue_missing_posts_task.rb @@ -0,0 +1,94 @@ +# typed: strict +# frozen_string_literal: true + +class Tasks::Inkbunny::EnqueueMissingPostsTask < EnqueueJobBase + extend T::Sig + include HasColorLogger + include Domain::Fa::HasCountFailedInQueue + + sig { override.returns(String) } + def progress_key + "task-inkbunny-enqueue-missing-posts" + end + + sig do + override + .params( + perform_max: T.nilable(Integer), + start_at: T.nilable(T.any(Integer, String)), + log_sink: T.any(IO, StringIO), + ) + .void + end + def initialize(perform_max: nil, start_at: nil, log_sink: $stderr) + super(perform_max:, log_sink:) + @start_at = + T.let( + get_progress(start_at&.to_s)&.to_i || + T.cast(Domain::Post::InkbunnyPost.maximum(:ib_id), Integer), + Integer, + ) + end + + sig { override.void } + def start_enqueuing + log("starting from ib_id: #{@start_at}") if @start_at + + total_processed = 0 + max_ib_post_id = @start_at + + loop do + min_ib_post_id = [max_ib_post_id - 10_000, 0].max + + missing_ib_post_ids_sql = <<~SQL + SELECT series.id + FROM generate_series(#{min_ib_post_id}, #{max_ib_post_id}) AS series(id) + LEFT JOIN domain_posts_ib_aux AS posts + ON series.id = posts.ib_id + WHERE posts.ib_id IS NULL + ORDER BY series.id DESC + LIMIT 100 + SQL + + missing_ib_post_ids = + ActiveRecord::Base + .connection + .execute(missing_ib_post_ids_sql) + .values + .flatten + .map(&:to_i) + missing_ib_post_ids = T.cast(missing_ib_post_ids, T::Array[Integer]) + + if found_min_id = missing_ib_post_ids.min + enqueue do + ColorLogger.quiet do + Domain::Inkbunny::Job::UpdatePostsJob.perform_now( + ib_post_ids: missing_ib_post_ids, + ) + end + end + # Move to continue from the lowest ID we just processed + max_ib_post_id = found_min_id + + total_processed += missing_ib_post_ids.size + logger.info( + format_tags( + make_tags(total_processed:, this_batch: missing_ib_post_ids.size), + ), + ) + else + # No missing IDs found in this large range, move the window down + max_ib_post_id = min_ib_post_id + end + + # Stop if we've reached the beginning + save_progress([max_ib_post_id, 0].max.to_s) + break if max_ib_post_id <= 0 + end + end + + sig { override.returns(Integer) } + def queue_size + count_failed_in_queue("inkbunny") + end +end diff --git a/app/models/domain/post_group.rb b/app/models/domain/post_group.rb index 14f0d0f4..1f0e9338 100644 --- a/app/models/domain/post_group.rb +++ b/app/models/domain/post_group.rb @@ -3,6 +3,7 @@ class Domain::PostGroup < ReduxApplicationRecord extend T::Helpers include AttrJsonRecordAliases include HasCompositeToParam + include HasDomainType self.table_name = "domain_post_groups" abstract! diff --git a/app/models/domain/post_group/e621_pool.rb b/app/models/domain/post_group/e621_pool.rb index 20641bcb..c19ded84 100644 --- a/app/models/domain/post_group/e621_pool.rb +++ b/app/models/domain/post_group/e621_pool.rb @@ -7,4 +7,9 @@ class Domain::PostGroup::E621Pool < Domain::PostGroup def self.param_prefix_and_attribute ["e621", :e621_id] end + + sig { override.returns(Domain::DomainType) } + def self.domain_type + Domain::DomainType::E621 + end end diff --git a/app/models/domain/post_group/inkbunny_pool.rb b/app/models/domain/post_group/inkbunny_pool.rb index e3644cd1..c94c099d 100644 --- a/app/models/domain/post_group/inkbunny_pool.rb +++ b/app/models/domain/post_group/inkbunny_pool.rb @@ -25,4 +25,9 @@ class Domain::PostGroup::InkbunnyPool < Domain::PostGroup "https://inkbunny.net/submissionsviewall.php?pool_id=#{self.ib_id}" end end + + sig { override.returns(Domain::DomainType) } + def self.domain_type + Domain::DomainType::Inkbunny + end end diff --git a/app/models/domain/post_group/sofurry_folder.rb b/app/models/domain/post_group/sofurry_folder.rb index 82765cb7..947c35c3 100644 --- a/app/models/domain/post_group/sofurry_folder.rb +++ b/app/models/domain/post_group/sofurry_folder.rb @@ -26,4 +26,9 @@ class Domain::PostGroup::SofurryFolder < Domain::PostGroup "https://www.sofurry.com/browse/folder/#{type}?by=#{owner_id}&folder=#{sofurry_id}" end end + + sig { override.returns(Domain::DomainType) } + def self.domain_type + Domain::DomainType::Sofurry + end end diff --git a/app/views/good_job/_custom_job_details.html.erb b/app/views/good_job/_custom_job_details.html.erb index 00d70e10..e7c3277b 100644 --- a/app/views/good_job/_custom_job_details.html.erb +++ b/app/views/good_job/_custom_job_details.html.erb @@ -25,6 +25,8 @@ <%= render "good_job/arguments/domain_user", user: job_arg.value %> <% when Domain::UserAvatar %> <%= render "good_job/arguments/domain_user_avatar", user_avatar: job_arg.value %> + <% when Domain::PostGroup %> + <%= render "good_job/arguments/domain_post_group", post_group: job_arg.value %> <% when GoodJob::Job %> <%= render "good_job/arguments/good_job_job", job: job_arg.value %> <% else %> diff --git a/app/views/good_job/arguments/_domain_post_group.html.erb b/app/views/good_job/arguments/_domain_post_group.html.erb new file mode 100644 index 00000000..9f376d0c --- /dev/null +++ b/app/views/good_job/arguments/_domain_post_group.html.erb @@ -0,0 +1,50 @@ +<%# Display post group information with associated details %> +