FIX: missing theme upload should not break precompile process. (#18431)

Previously, if an active default theme's upload record went missing then it will break the site and cause downtime.
This commit is contained in:
Vinoth Kannan 2022-09-30 10:48:26 +05:30 committed by GitHub
parent 0bdb616edc
commit 6ebd2cecda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -222,7 +222,7 @@ class Stylesheet::Manager::Builder
sha1s = []
(theme&.upload_fields || []).map do |upload_field|
sha1s << upload_field.upload.sha1
sha1s << upload_field.upload&.sha1
end
Digest::SHA1.hexdigest(sha1s.sort!.join("\n"))

View File

@ -351,6 +351,37 @@ RSpec.describe Stylesheet::Manager do
expect(digest1).not_to eq(digest2)
end
it 'can generate digest with a missing upload record' do
theme = Fabricate(:theme)
upload = UploadCreator.new(image, "logo.png").create_for(-1)
field = ThemeField.create!(
theme_id: theme.id,
target_id: Theme.targets[:common],
name: "logo",
value: "",
upload_id: upload.id,
type_id: ThemeField.types[:theme_upload_var]
)
manager = manager(theme.id)
builder = Stylesheet::Manager::Builder.new(
target: :desktop_theme, theme: theme, manager: manager
)
digest1 = builder.digest
upload.delete
builder = Stylesheet::Manager::Builder.new(
target: :desktop_theme, theme: theme.reload, manager: manager
)
digest2 = builder.digest
expect(digest1).not_to eq(digest2)
end
it 'returns different digest based on target' do
theme = Fabricate(:theme)
builder = Stylesheet::Manager::Builder.new(target: :desktop_theme, theme: theme, manager: manager)