Curious about serializer optimization #9559
Unanswered
Antoliny0919
asked this question in
Question & Answer
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm curious about serializer optimization, so I created a post on discussion.
Suppose that there is a test model called Wagon and that there is large data in the stuff field in the model object.
If the list view does not require stuff data, apply a defer method to the query set.
When I applied the following ModelSerializer in this state, contrary to my expectation, the stuff field value of the Wagon object was also obtained.
When I removed certain columns from the query using defer, I thought Serializer wouldn't get them either.
So it was a loss in terms of speed if it provided a stuff field value that was unnecessary and had a large data.
First of all, I was curious about How can serializer get stuff field values, so I looked up data property logic.
rest_framework/fields.py
I found the answer to this part in the code above. I set the fields of the serializer to all so I was supposed to get all the fields, and I was able to get the stuff field value even if I applied defer to the instant.
(I think my understanding of this part is not enough)
I for solve the problem removed stuff from serializer through exclude and changed the serializer of logic that needed stuff as follows.
I wonder if the way I did it for optimization is right.
Can you give me a good opinion or solution?
Beta Was this translation helpful? Give feedback.
All reactions