DEV: Cleanup topic thumbnail enqueuing (#17119)

- Ensure only one job is enqueued when there are no extra sizes requested by themes
- Update and un-skip relevant tests
This commit is contained in:
David Taylor 2022-06-17 11:07:32 +01:00 committed by GitHub
parent 1166db12b4
commit 6695d148d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 8 deletions

View File

@ -85,8 +85,7 @@ class Topic < ActiveRecord::Base
if SiteSetting.create_thumbnails && if SiteSetting.create_thumbnails &&
enqueue_if_missing && enqueue_if_missing &&
records.length < thumbnail_sizes.length && records.length < thumbnail_sizes.length &&
Discourse.redis.set(thumbnail_job_redis_key(thumbnail_sizes), 1, nx: true, ex: 1.minute) Discourse.redis.set(thumbnail_job_redis_key(extra_sizes), 1, nx: true, ex: 1.minute)
Jobs.enqueue(:generate_topic_thumbnails, { topic_id: id, extra_sizes: extra_sizes }) Jobs.enqueue(:generate_topic_thumbnails, { topic_id: id, extra_sizes: extra_sizes })
end end

View File

@ -37,13 +37,18 @@ describe "Topic Thumbnails" do
end end
it "includes the theme specified resolutions" do it "includes the theme specified resolutions" do
pending "We're creating two generate topic thumbnails jobs instead of one"
topic_json = nil topic_json = nil
expect do expect do
topic_json = get_topic topic_json = get_topic
end.to change { Jobs::GenerateTopicThumbnails.jobs.size }.by(1) end.to change { Jobs::GenerateTopicThumbnails.jobs.size }.by(2)
expect(
Jobs::GenerateTopicThumbnails.jobs.map { |j| j["args"][0]["extra_sizes"] }
).to eq([
nil, # Job for core/plugin sizes
[[10, 10], [20, 20], [30, 30]]] # Job for theme sizes
)
thumbnails = topic_json["thumbnails"] thumbnails = topic_json["thumbnails"]
@ -92,8 +97,6 @@ describe "Topic Thumbnails" do
end end
it "includes the theme specified resolutions" do it "includes the theme specified resolutions" do
pending "We're creating two generate topic thumbnails jobs instead of one"
topic_json = nil topic_json = nil
expect do expect do

View File

@ -70,7 +70,7 @@ describe TopicViewSerializer do
it 'should have thumbnail jobs enqueued' do it 'should have thumbnail jobs enqueued' do
SiteSetting.create_thumbnails = true SiteSetting.create_thumbnails = true
Discourse.redis.del(topic.thumbnail_job_redis_key(Topic.thumbnail_sizes)) Discourse.redis.del(topic.thumbnail_job_redis_key([]))
json = nil json = nil
expect do expect do