-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Prevent creation of unnecessary fieldset(mirror and revised) #2450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 0-10-stable
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,11 @@ module Adapter | |
class Attributes < Base | ||
def initialize(*) | ||
super | ||
instance_options[:fieldset] ||= ActiveModel::Serializer::Fieldset.new(fields_to_fieldset(instance_options.delete(:fields))) | ||
|
||
instance_options[:fieldset] ||= begin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change#1: only initialize
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine. Or add a class method on fieldset which does what's in this begin block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. echoing what you previously mentioned, I also want keep the changes minimal 🙏 |
||
fieldset = fields_to_fieldset(instance_options.delete(:fields)) | ||
fieldset && ActiveModel::Serializer::Fieldset.new(fieldset) | ||
end | ||
end | ||
|
||
def serializable_hash(options = nil) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ def self.fragment_cache(cached_hash, non_cached_hash, root = true) | |
def initialize(serializer, options = {}) | ||
super | ||
@include_directive = JSONAPI::IncludeDirective.new(options[:include], allow_wildcard: true) | ||
@fieldset = options[:fieldset] || ActiveModel::Serializer::Fieldset.new(options.delete(:fields)) | ||
@fieldset = options[:fieldset] || ((option_fields = options.delete(:fields)) && ActiveModel::Serializer::Fieldset.new(option_fields)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
|
||
# {http://jsonapi.org/format/#crud Requests are transactional, i.e. success or failure} | ||
|
@@ -348,7 +348,8 @@ def data_for(serializer, include_slice) | |
data.tap do |resource_object| | ||
next if resource_object.nil? | ||
# NOTE(BF): the attributes are cached above, separately from the relationships, below. | ||
requested_associations = fieldset.fields_for(resource_object[:type]) || '*' | ||
requested_fields = fieldset && fieldset.fields_for(resource_object[:type]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this is not a change, it just saves the also align with above |
||
requested_associations = requested_fields || '*' | ||
relationships = relationships_for(serializer, requested_associations, include_slice) | ||
resource_object[:relationships] = relationships if relationships.any? | ||
end | ||
|
Uh oh!
There was an error while loading. Please reload this page.