mirror of
https://github.com/discourse/discourse.git
synced 2025-02-12 12:19:49 +08:00
![Alan Guo Xiang Tan](/assets/img/avatar_default.png)
Why this change? When creating a new theme setting that does not have a corresponding row in the `theme_settings` table, we end up writing to the database twice because `ActiveRecord::Base#save!` is called once before the `value` or `json_value` column is updated again with another database query with another call to `ActiveRecord::Base#save!`. What does this change do? Adds the column to be updated to argument for the `ActiveRecord::Base#create!` method call so that we only have one write query to the database.
19 lines
433 B
Ruby
19 lines
433 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ThemeSettingsManager::Objects < ThemeSettingsManager
|
|
def value
|
|
has_record? ? db_record.json_value : default.map!(&:deep_stringify_keys)
|
|
end
|
|
|
|
def value=(objects)
|
|
ensure_is_valid_value!(objects)
|
|
record = has_record? ? update_record!(json_value: objects) : create_record!(json_value: objects)
|
|
theme.reload
|
|
record.json_value
|
|
end
|
|
|
|
def schema
|
|
@opts[:schema]
|
|
end
|
|
end
|