Skip to content
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

Renderer adding an extra call to the DB for resources collection #106

Open
benoror opened this issue Aug 15, 2024 · 3 comments
Open

Renderer adding an extra call to the DB for resources collection #106

benoror opened this issue Aug 15, 2024 · 3 comments

Comments

@benoror
Copy link

benoror commented Aug 15, 2024

When using jsonapi: renderer I found out it was effectively adding an extra call to the resources, impacting performance:

Screenshot 2024-08-15 at 1 22 38 p m

Compare results when using Rails' default json: rednerer and jsonapi-serializer directly:

Screenshot 2024-08-15 at 1 26 24 p m
@benoror
Copy link
Author

benoror commented Aug 15, 2024

It's actually adding the 2 extra prev. steps of Property Count and Property Exists? as well

@stas
Copy link
Owner

stas commented Aug 27, 2024

@benoror could you share your serializer implementation?

Also this is probably an issue for the https://github.com/jsonapi-serializer/jsonapi-serializer/ ?

@benoror
Copy link
Author

benoror commented Aug 27, 2024

Also this is probably an issue for the https://github.com/jsonapi-serializer/jsonapi-serializer/ ?

The second example is only using jsonapi-serializer (sans jsonapi.rb wrapper) and it's clearly not causing it AFAICT

@benoror could you share your serializer implementation?

class PropertySerializer
  include JSONAPI::Serializer

  belongs_to :broker
  belongs_to :status, serializer: :tag, id_method_name: :status_tag_key
  belongs_to :type, serializer: :tag, id_method_name: :type_tag_key
  belongs_to :location, serializer: :tag, id_method_name: :location_tag_key
  belongs_to :agent, serializer: :account
  has_many :features

  attributes :title, :description, :published, :built_at,
             :retail_price, :retail_price_cents, :retail_price_currency,
             :rent_price, :rent_price_cents, :rent_price_currency,
             :rto_price, :rto_price_cents, :rto_price_currency,
             :rooms, :bathrooms, :floors, :parking_lots, :video_url,
             :area, :area_units, :land_area, :land_area_units,
             :latitude, :longitude, :street_address, :street_number, :postal_code

  attribute :images do |object|
    attachments(object.images)
  end

  attribute :plans do|object|
    attachments(object.plans)
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants