Skip to content

Commit

Permalink
FIX: Avoid infinite loop if disk space is low
Browse files Browse the repository at this point in the history
We now continue to enqueue the pull_hotlinked_images job for optimized images, even if disk space is low
  • Loading branch information
davidtaylorhq committed Jun 7, 2019
1 parent fca9010 commit e3a9a2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/cooked_post_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def enforce_nofollow

def pull_hotlinked_images(bypass_bump = false)
# 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
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
Expand All @@ -640,6 +640,7 @@ def pull_hotlinked_images(bypass_bump = false)
end

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

SiteSetting.download_remote_images_to_local = false
Expand Down
13 changes: 8 additions & 5 deletions spec/components/cooked_post_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1094,10 +1094,10 @@
SiteSetting.download_remote_images_to_local = true
end

it "does not run when there is not enough disk space" do
cpp.expects(:disable_if_low_on_disk_space).returns(true)
Jobs.expects(:cancel_scheduled_job).never
it "disables download_remote_images if there is not enough disk space" do
cpp.expects(:available_disk_space).returns(5)
cpp.pull_hotlinked_images
expect(SiteSetting.download_remote_images_to_local).to eq(false)
end

context "and there is enough disk space" do
Expand Down Expand Up @@ -1136,11 +1136,14 @@
let(:post) { build(:post, created_at: 20.days.ago) }
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
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)
end

Expand Down

0 comments on commit e3a9a2d

Please sign in to comment.