-
Notifications
You must be signed in to change notification settings - Fork 301
Issue #337 #366
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
Issue #337 #366
Conversation
…ormance expectations (also flake8)
…viewset to help with prefetching includes.
Add Django Debug Toolbar, and add a failing test for query explosions
Add a helper for specifying a prefetch_for_related attribute on your viewset to help with prefetching includes.
Codecov Report
@@ Coverage Diff @@
## develop #366 +/- ##
=========================================
+ Coverage 92.81% 93% +0.19%
=========================================
Files 51 51
Lines 2644 2659 +15
=========================================
+ Hits 2454 2473 +19
+ Misses 190 186 -4
Continue to review full report at Codecov.
|
Looks great! |
@jsenecal It looks like Travis is failing because of isort (curiously, only Python 3.4 🤔 ). I think isort gets a little tricky because the config file is trying to be correct for the rest_framework_json_api, but it also has to satisfy the included example package. I'm guessing you can solve this by including $ isort --check-only --verbose --recursive --diff --thirdparty pytest \
--thirdparty polymorphic --thirdparty pytest_factoryboy \
--thirdparty packaging example I'll look at the code closer to give it some review. |
*.sw* | ||
manage.py |
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.
Why is this ignoring manage.py
?
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.
@aidanlister must have a custom one (introduced by da0c94c).
We're not using it to start the app anyways ($ django-admin.py runserver --settings=example.settings
)
example/settings/dev.py
Outdated
# If performance testing, enable: | ||
'example.utils.BrowsableAPIRendererWithoutForms', | ||
# Otherwise, to play around with the browseable API, enable: | ||
# 'rest_framework.renderers.BrowsableAPIRenderer', |
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.
Since example
is what runs on the demo site, should we leave the form version on by default instead of the perf version so that people can add extra data to play with it?
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.
I guess it would make sense indeed - let me fix this
from django.utils.translation import ugettext_lazy as _ | ||
from rest_framework.fields import MISSING_ERROR_MESSAGE | ||
from rest_framework.relations import * # noqa: F403 | ||
from rest_framework.relations import MANY_RELATION_KWARGS, PrimaryKeyRelatedField |
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.
👏 I'm a fan of any time a *
import can be removed.
I like what's here a lot! What do you think about documentation for this stuff? IMO, features don't really exist until they are documented so that users know how to use them. With that stated, it doesn't matter to me if the features are documented in this branch or in some other branch as long as there is some prose before in the docs before the next release. Once Travis is green, I'm ok with merging. If you decide to add some docs, I can give it another look. Thanks for pulling this together with @aidanlister. 👍 |
@@ -74,8 +74,13 @@ class AuthorViewSet(ModelViewSet): | |||
|
|||
|
|||
class CommentViewSet(ModelViewSet): | |||
queryset = Comment.objects.all() | |||
queryset = Comment.objects.select_related('author', 'entry') |
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.
I still have an issue with the way relations are extracted first level... I had to prefetch things that I shouldn't have to only to make tests pass... Feels like the queryset might be over reaching to overcome an issue with drf_jsonapi.
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.
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.
After further investigation, the problem does not occur inside extract_relationships - Still looking
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.
@jsenecal the problem is in two places, setting use_pk_only_optimization to False, and extract_attributes. You have to whack them both, which made it so hard to find the source of the explosion.
I think you should probably remove the select_related in this because the tests should fail until we fix that other issue?
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.
Thanks for this - I merged already but will update my branch to reflect this conversation
@jsenecal thanks for including my cite, might be better to give some context there though? Let me write something: |
No need to cite me, my paragraph in that issue is about the query explosion from displaying FKs -- let's merge this and we'll keep working out of that issue. |
Thanks to @aidanlister for his contribution on this.