PERF: Remove unnecessary queries from Theme#set_field (#21281)

This commit is contained in:
Daniel Waterworth 2023-04-27 13:04:58 -05:00 committed by GitHub
parent 3527fbcd8e
commit ae63d9ea09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -494,11 +494,11 @@ class Theme < ActiveRecord::Base
value ||= ""
field =
theme_fields.find { |f| f.name == name && f.target_id == target_id && f.type_id == type_id }
field = theme_fields.find_by(name: name, target_id: target_id, type_id: type_id)
if field
if value.blank? && !upload_id
theme_fields.delete field.destroy
field.destroy
else
if field.value != value || field.upload_id != upload_id
field.value = value