Skip to content

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.rb
index 8c3464b53b5..82a63ab00f3 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -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