1+N querys

I am developer/code-reviewer/debugger/bug-fixer/architect/teacher/builder from dubai, uae
Search for a command to run...

I am developer/code-reviewer/debugger/bug-fixer/architect/teacher/builder from dubai, uae
No comments yet. Be the first to comment.
You Should Tell Yourself

A URL shortener is a proxy service that provides a mapping between the short and full representation of a URL. The short URL has the advantage of being small. The service can also provide useful analy

Listening to the Mel Robbins's podcast on regrets was a 'ear'-opener. One can have reqrets of action or inaction. 4 types of reqrets foundation - should've done the work boldness - should've taken t

We need to create a unique ID generator for our high-traffic web application, generating about 10K IDs/second. The IDs can't simply be monotonically increasing integers, which are good for data access
doing + telling

Widely know as N+plus one problem, it’s actually a misnomer. As @adamj.eu’s article neatly summarize with examples (and now my dyslexic mind actually understands it), it’s one query to get a list of N objects that you iterate over. And each iteration is a query as the initial query is lazy evaluated.
To avoid this in django, use:
select_related (for one-to-one or one-to-many queries)
prefetch_related (for many-to-many, many-to-one or generic-relations queries)
where it gets the related rows with the initial query, as the name indicates.
Always try and minimize the queries to a shared resource.
Happy hackin’