mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 22:21:19 +08:00
FIX: Avoid infinite loop if disk space is low
We now continue to enqueue the pull_hotlinked_images job for optimized images, even if disk space is low
This commit is contained in:
@ -627,7 +627,7 @@ class CookedPostProcessor
|
|||||||
|
|
||||||
def pull_hotlinked_images(bypass_bump = false)
|
def pull_hotlinked_images(bypass_bump = false)
|
||||||
# have we enough disk space?
|
# have we enough disk space?
|
||||||
return if disable_if_low_on_disk_space
|
disable_if_low_on_disk_space # But still enqueue the job
|
||||||
# don't download remote images for posts that are more than n days old
|
# don't download remote images for posts that are more than n days old
|
||||||
return unless @post.created_at > (Date.today - SiteSetting.download_remote_images_max_days_old)
|
return unless @post.created_at > (Date.today - SiteSetting.download_remote_images_max_days_old)
|
||||||
# we only want to run the job whenever it's changed by a user
|
# we only want to run the job whenever it's changed by a user
|
||||||
@ -640,6 +640,7 @@ class CookedPostProcessor
|
|||||||
end
|
end
|
||||||
|
|
||||||
def disable_if_low_on_disk_space
|
def disable_if_low_on_disk_space
|
||||||
|
return false if !SiteSetting.download_remote_images_to_local
|
||||||
return false if available_disk_space >= SiteSetting.download_remote_images_threshold
|
return false if available_disk_space >= SiteSetting.download_remote_images_threshold
|
||||||
|
|
||||||
SiteSetting.download_remote_images_to_local = false
|
SiteSetting.download_remote_images_to_local = false
|
||||||
|
@ -1094,10 +1094,10 @@ describe CookedPostProcessor do
|
|||||||
SiteSetting.download_remote_images_to_local = true
|
SiteSetting.download_remote_images_to_local = true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not run when there is not enough disk space" do
|
it "disables download_remote_images if there is not enough disk space" do
|
||||||
cpp.expects(:disable_if_low_on_disk_space).returns(true)
|
cpp.expects(:available_disk_space).returns(5)
|
||||||
Jobs.expects(:cancel_scheduled_job).never
|
|
||||||
cpp.pull_hotlinked_images
|
cpp.pull_hotlinked_images
|
||||||
|
expect(SiteSetting.download_remote_images_to_local).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "and there is enough disk space" do
|
context "and there is enough disk space" do
|
||||||
@ -1136,11 +1136,14 @@ describe CookedPostProcessor do
|
|||||||
let(:post) { build(:post, created_at: 20.days.ago) }
|
let(:post) { build(:post, created_at: 20.days.ago) }
|
||||||
let(:cpp) { CookedPostProcessor.new(post) }
|
let(:cpp) { CookedPostProcessor.new(post) }
|
||||||
|
|
||||||
before { cpp.expects(:available_disk_space).returns(50) }
|
before do
|
||||||
|
SiteSetting.download_remote_images_to_local = true
|
||||||
|
cpp.expects(:available_disk_space).returns(50)
|
||||||
|
end
|
||||||
|
|
||||||
it "does nothing when there's enough disk space" do
|
it "does nothing when there's enough disk space" do
|
||||||
SiteSetting.expects(:download_remote_images_threshold).returns(20)
|
SiteSetting.expects(:download_remote_images_threshold).returns(20)
|
||||||
SiteSetting.expects(:download_remote_images_to_local).never
|
SiteSetting.expects(:download_remote_images_to_local=).never
|
||||||
expect(cpp.disable_if_low_on_disk_space).to eq(false)
|
expect(cpp.disable_if_low_on_disk_space).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user