Enqueue links after browse page scan so title/creator is set

This commit is contained in:
Dylan Knutson
2025-06-18 16:40:22 +00:00
parent 94533b6e45
commit dc98e30f47
5 changed files with 35 additions and 12 deletions

View File

@@ -57,8 +57,6 @@ class Domain::Fa::Job::BrowsePageJob < Domain::Fa::Job::Base
)
end
enqueue_jobs_from_found_links(response.log_entry)
page = Domain::Fa::Parser::Page.new(response.body)
listing_page_stats =
update_and_enqueue_posts_from_listings_page(
@@ -66,6 +64,8 @@ class Domain::Fa::Job::BrowsePageJob < Domain::Fa::Job::Base
page_parser: page,
)
enqueue_jobs_from_found_links(response.log_entry)
@total_num_new_posts_seen += listing_page_stats.new_posts.count
@total_num_posts_seen += listing_page_stats.all_posts.count
listing_page_stats.new_posts.count > 0

View File

@@ -154,11 +154,14 @@ class Domain::Post::FaPost < Domain::Post
{ url_name: submission.artist_url_name },
) { |user| user.name = submission.artist }
Domain::Post::FaPost.find_or_initialize_by(fa_id: submission.id) do |post|
post.creator = creator
post.title = submission.title
post.first_seen_entry = first_seen_log_entry
end
post =
Domain::Post::FaPost.find_or_initialize_by(fa_id: submission.id) do |post|
post.first_seen_entry = first_seen_log_entry
end
post.creator ||= creator
post.title ||= submission.title
post
end
sig { override.returns(T.nilable(ActiveSupport::TimeWithZone)) }

View File

@@ -9,13 +9,12 @@ module PerformJobHelpers
params(
params: T::Hash[Symbol, T.untyped],
should_raise: T.any(T::Boolean, T.class_of(Exception), String, Regexp),
skip_enqueue_found_links: T::Boolean,
).returns(T.untyped)
end
def perform_now(params, should_raise: false)
def perform_now(params, should_raise: false, skip_enqueue_found_links: true)
ret =
described_class.perform_now(
{ skip_enqueue_found_links: true }.merge(params),
)
described_class.perform_now({ skip_enqueue_found_links: }.merge(params))
bt_printer =
Kernel.proc do

View File

@@ -36,7 +36,7 @@ RSpec.describe Domain::E621::Job::ScanUserFavsJob do
}.from(nil).to("ok")
# Verify the posts were created
expect(Domain::Post::E621Post.pluck(:e621_id)).to eq(
expect(Domain::Post::E621Post.pluck(:e621_id)).to match_array(
[5_212_363, 5_214_461, 5_306_537, 2_518_409, 5_129_881],
)
expect(Domain::UserPostFav.count).to eq(5)

View File

@@ -219,6 +219,27 @@ describe Domain::Fa::Job::BrowsePageJob do
expect(find_post.call.state).to eq("ok")
expect(find_post.call.title).to eq("reminder YCH AUCTION")
expect(find_post.call.creator).to eq(find_creator.call)
expect(SpecUtil.enqueued_job_args).to match(
[
hash_including({ post: find_post.call }),
hash_including({ user: find_creator.call }),
],
)
end
it "creates a post when enqueueing found links" do
perform_now({ skip_enqueue_found_links: false })
expect(find_post.call.state).to eq("ok")
expect(find_post.call.title).to eq("reminder YCH AUCTION")
expect(find_post.call.creator).to eq(find_creator.call)
expect(SpecUtil.enqueued_job_args(Domain::Fa::Job::UserPageJob)).to match(
including(
hash_including(
{ user: find_creator.call, caused_by_entry: log_entries[0] },
),
),
)
end
it "creates a user with the right attributes" do