account for posts with replacement files
This commit is contained in:
@@ -73,15 +73,21 @@ module Domain::E621::Job
|
||||
|
||||
e621_md5 = post_json["file"]["md5"]
|
||||
if post.md5 && post.md5 != e621_md5
|
||||
logger.error(
|
||||
"[ id: #{post.id} / e621_id: #{post.e621_id} ] " +
|
||||
"md5 mismatch for post: #{post.md5} != #{e621_md5}"
|
||||
logger.warn(
|
||||
"md5 changed for post: #{post.md5.to_s.bold} => #{e621_md5.to_s.bold}"
|
||||
)
|
||||
return false
|
||||
post.state_detail["prev_md5s"] ||= []
|
||||
post.state_detail["prev_md5s"] << {
|
||||
"md5" => post.md5,
|
||||
"file_id" => post.file_id,
|
||||
}
|
||||
post.file = nil
|
||||
file_changed = true
|
||||
else
|
||||
post.md5 = e621_md5
|
||||
file_changed = false
|
||||
end
|
||||
|
||||
post.md5 = e621_md5
|
||||
post.file_url_str ||= post_json["file"]["url"]
|
||||
post.description = post_json["description"]
|
||||
post.rating = post_json["rating"]
|
||||
@@ -112,7 +118,7 @@ module Domain::E621::Job
|
||||
defer_job(Domain::E621::Job::StaticFileJob, {
|
||||
post: post,
|
||||
caused_by_entry: @log_entry,
|
||||
}) if new_record
|
||||
}) if new_record || file_changed
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
@@ -50,6 +50,9 @@ describe Domain::E621::Job::PostsIndexJob do
|
||||
post.save!
|
||||
|
||||
perform_now({})
|
||||
expect(SpecUtil.enqueued_jobs(
|
||||
Domain::E621::Job::StaticFileJob
|
||||
).length).to eq(4)
|
||||
|
||||
post.reload
|
||||
# removes the tag1 tag
|
||||
@@ -64,5 +67,27 @@ describe Domain::E621::Job::PostsIndexJob do
|
||||
tagging.tag.name == "mammal"
|
||||
}.category).to eq("cat_species")
|
||||
end
|
||||
|
||||
it "updates a post where the md5 has changed" do
|
||||
file = SpecUtil.create_http_log_entry
|
||||
post = Domain::E621::Post.create!({
|
||||
e621_id: 4247443,
|
||||
md5: "0000000051668681e9697a48144d7c78",
|
||||
file: file,
|
||||
})
|
||||
perform_now({})
|
||||
post.reload
|
||||
expect(post.md5).to eq("1c6169aa51668681e9697a48144d7c78")
|
||||
expect(post.file).to be_nil
|
||||
expect(post.state_detail["prev_md5s"]).to eq([
|
||||
"md5" => "0000000051668681e9697a48144d7c78",
|
||||
"file_id" => file.id,
|
||||
])
|
||||
static_file_jobs = SpecUtil.enqueued_jobs(Domain::E621::Job::StaticFileJob)
|
||||
expect(static_file_jobs.length).to eq(5)
|
||||
expect(static_file_jobs).to match(
|
||||
including(including(args: [including(post: post)]))
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user