Skip to content

Improve performance of extract_related() #532

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ Mohammed Ali Zubair <mazg1493@gmail.com>
Jason Housley <housleyjk@gmail.com>
Beni Keller <beni@matraxi.ch>
Stas S. <stas@nerd.ro>
Juha Yrjölä <juha.yrjola@iki.fi>
Nathanael Gordon <nathanael.l.gordon@gmail.com>
Charlie Allatson <charles.allatson@gmail.com>
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ This is the last release supporting Python 2.7, Python 3.4, Django Filter 1.1, D
* Allow `HyperlinkRelatedField` to be used with [related urls](https://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html?highlight=related%20links#related-urls)
* Avoid exception in `AutoPrefetchMixin` when including a reverse one to one relation ([#537](https://github.com/django-json-api/django-rest-framework-json-api/issues/537))
* Avoid requested resource(s) to be added to included as well ([#524](https://github.com/django-json-api/django-rest-framework-json-api/issues/524))
* Performance improvement when rendering included data

## [2.6.0] - 2018-09-20

Expand Down
9 changes: 8 additions & 1 deletion rest_framework_json_api/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ def extract_included(cls, fields, resource, resource_instance, included_resource
relation_type or
utils.get_resource_type_from_instance(nested_resource_instance)
)
resource_id = encoding.force_text(nested_resource_instance.pk)
if included_cache.get(resource_type, {}).get(resource_id):
# Do not serialize if already included in the response
continue
serializer_fields = utils.get_serializer_fields(
serializer.__class__(
nested_resource_instance, context=serializer.context
Expand All @@ -421,7 +425,10 @@ def extract_included(cls, fields, resource, resource_instance, included_resource

if isinstance(field, Serializer):
relation_type = utils.get_resource_type_from_serializer(field)

resource_id = encoding.force_text(relation_instance.pk)
if included_cache.get(relation_type, {}).get(resource_id):
# Do not serialize if already included in the response
continue
# Get the serializer fields
serializer_fields = utils.get_serializer_fields(field)
if serializer_data:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy