discourse/app/serializers/theme_field_serializer.rb
Mark VanLandingham 012aaf0ba3
PERF: Don't serialize value for theme_fields unnecessarily (#21201)
The value field of ThemeField is only used when viewing a diff in the staff action logs and local theme editing. value is being serialized into the theme index as well, which is not used. It's a huge amount of JSON that we can cut by removing it.

This also breaks up the various theme serializers into separate classes so they autoload properly (or at least restart the server on edit)
2023-04-24 09:30:51 -05:00

38 lines
599 B
Ruby

# frozen_string_literal: true
class ThemeFieldSerializer < ApplicationSerializer
attributes :name, :target, :value, :error, :type_id, :upload_id, :url, :filename
def include_url?
object.upload
end
def include_upload_id?
object.upload
end
def include_filename?
object.upload
end
def url
object.upload&.url
end
def filename
object.upload&.original_filename
end
def include_value?
@options[:include_value] || false
end
def target
Theme.lookup_target(object.target_id)&.to_s
end
def include_error?
object.error.present?
end
end