mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
FIX: Add onceoff job to remove double quotes from s3 etags
This commit is contained in:
parent
7b5931013a
commit
484bd82278
11
app/jobs/onceoff/fix_s3_etags.rb
Normal file
11
app/jobs/onceoff/fix_s3_etags.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Jobs
|
||||
class FixS3Etags < Jobs::Onceoff
|
||||
|
||||
def execute_onceoff(args)
|
||||
[Upload, OptimizedImage].each do |model|
|
||||
sql = "UPDATE #{model.table_name} SET etag = REGEXP_REPLACE(etag, '\"', '', 'g') WHERE etag LIKE '\"%\"'"
|
||||
DB.exec(sql)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
22
spec/jobs/fix_s3_etags_spec.rb
Normal file
22
spec/jobs/fix_s3_etags_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Jobs::FixS3Etags do
|
||||
let(:etag_with_quotes) { '"ETag"' }
|
||||
let(:etag_without_quotes) { 'ETag' }
|
||||
|
||||
it 'should remove double quotes from etags' do
|
||||
upload1 = Fabricate(:upload, etag: etag_with_quotes)
|
||||
upload2 = Fabricate(:upload, etag: etag_without_quotes)
|
||||
optimized = Fabricate(:optimized_image, etag: etag_with_quotes)
|
||||
|
||||
described_class.new.execute_onceoff({})
|
||||
|
||||
upload1.reload
|
||||
upload2.reload
|
||||
optimized.reload
|
||||
|
||||
expect(upload1.etag).to eq(etag_without_quotes)
|
||||
expect(upload2.etag).to eq(etag_without_quotes)
|
||||
expect(optimized.etag).to eq(etag_without_quotes)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user