A platform for community discussion. Free, open, simple.
PERF: Remove unnecessary queries from Theme#set_field (#21281)
Daniel Waterworthae63d9ea09f6
diff --git a/app/models/theme.rb b/app/models/theme.rbindex 8c3464b53b5..82a63ab00f3 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -494,11 +494,11 @@ class Theme < ActiveRecord::Basevalue ||= ""- 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 fieldif value.blank? && !upload_id- theme_fields.delete field.destroy+ field.destroyelseif field.value != value || field.upload_id != upload_idfield.value = value