-
Notifications
You must be signed in to change notification settings - Fork 42
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
chore: Reduce number of queries by prefetching foreign key objects on comment #215
Conversation
abhiabhi94
commented
Jul 11, 2021
•
edited
Loading
edited
- the fetched objects are user, reaction and flag.
The performance gain will increase with the number of comments. For example, on my local database, when viewing the API Stats courtesy |
f0661eb
to
e1f349a
Compare
e1f349a
to
49c434a
Compare
Hey @Radi85, how are you? just wanted to check whether everything is okay with you. in case you don't have the time to review patches, maybe you can remove the review required restriction from the settings. This will allow me to merge pull-requests and continue the development of this project. It will also likely help me in making future releases. |
Hey @abhiabhi94, |
Hey @Radi85, why was this removed in 877d4e6 diff --git a/comment/api/serializers.py b/comment/api/serializers.py
index 5d5b29c..bc319dd 100644
--- a/comment/api/serializers.py
+++ b/comment/api/serializers.py
- def __init__(self, *args, **kwargs):
- user = kwargs['context']['request'].user
- self.email_service = None
- if user.is_authenticated or not settings.COMMENT_ALLOW_ANONYMOUS:
- del self.fields['email']
-
- super().__init__(*args, **kwargs) Now, i see |
It was removed intentionally since the email validation won't happen if the user is authenticated. With the current code we can create comment using curl. I am not sure why the validation is occurring while using djangorestframework UI. curl -X POST 'http://127.0.0.1:8001/api/comments/create/?app_name=post&model_name=post&model_id=1' -d '{"content": "test"}' -H "Content-Type: application/json" -u test:test Response: {"id":187,"user":{"username":"test","email":"test@test.com","id":3,"profile":{"display_name":null,"birth_date":null,"image":"/media/pic/default.png"}},"email":"test@test.com","content":"test","parent":null,"posted":"2021-07-20T06:06:19.429350Z","edited":"2021-07-20T06:06:30.284091Z","reply_count":0,"replies":[],"urlhash":"comment-ncoppzay"} In the ideal world, the api won't be consumed using the restframework UI. |
The code in contention isn't doing validation. It is just removing the field |
For the restframework UI, when the email is presented on the serializer, the validation is happening. That means the email was deleted from the init method to skip the validation. The above is not apply when using curl or fetch lib so INHO we don't need to delete the email field from the serializer. |
It is occurring because we have a method When using something like In an ideal scenario, we probably shouldn't have to manually call the |
As I said, this is happening when using the restframework UI but it does NOT when using external library unless we explicitly call |
The issue is that if the API is being used to create a form for frontend development using the |
49c434a
to
506a089
Compare
506a089
to
55ee286
Compare
… comment - the fetched objects are user, reaction and flag.
55ee286
to
aca7272
Compare
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 your time :)