-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Prevent creation of unnecessary fieldset(mirror and revised) #2450
base: 0-10-stable
Are you sure you want to change the base?
Prevent creation of unnecessary fieldset(mirror and revised) #2450
Conversation
@@ -348,7 +349,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 comment
The reason will be displayed to describe this comment to others. Learn more.
change#2: only ask for fields_for
when fieldset
is not nil
this is not a change, it just saves the fields_for
cost
also align with above
aa20faa
to
1af09b5
Compare
hello @bf4 , sorry about pinging directly, could you take a look when you have a moment ? 🙏 |
I'm on vacation and haven't read too carefully If tests pass and it works for people, that's fine with me There are some changes which are refactors which may introduce possible bugs. When that's the case, it's often worth extracting just the refactors and any work which supports the change you want, but doesn't change behavior, so that the actual code change which changes the behavior is smaller and safer and easier to review. That is, make a new pr without the behavior changes, merge it, then rebase/update the feature pr |
ok, let me separate the change from refactoring have a nice vacation :D |
26a1dd8
to
c34dc87
Compare
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
change#1: only initialize ActiveModel::Serializer::Fieldset
when fieldset is not nil
instance_options[:fieldset]
could be:
- the
fieldset
passed in through option ActiveModel::Serializer::Fieldset
instance- nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
echoing what you previously mentioned, I also want keep the changes minimal 🙏
if it's necessary, is it better to do it in another refactoring PR?
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
@fieldset
could be:
- the
fieldset
passed in through option ActiveModel::Serializer::Fieldset
instance- nil
Updated: only include desired changes for performance optimization |
40befea
to
73420cd
Compare
73420cd
to
a47c639
Compare
hello @bf4 , sorry to bother , just would like to see whether the changes looks good to you ? Orz |
Seems fine |
Purpose
see: #2370
Changes
ActiveModel::Serializer::Fieldset
when fieldset is not nilchange#2: only ask forfields_for
whenfieldset
is not nilCaveats
NA
Related GitHub issues
Additional helpful information