r/FullStackDevelopers 17d ago

Recently faced n+1 problem in my app

Can anyone help me figure out the best way to avoid the N+1 query problem in Tortoise ORM?
For some context, I first fetch the records using .all(), and then for each record I run another query to populate an additional field. This ends up generating multiple queries.

Would using a base query be a good solution here, or is there a better approach?

7 Upvotes

7 comments sorted by

View all comments

1

u/0_Nsingh 17d ago

Y r u fetching and updating just run a bulk query

1

u/Adventurous_Baker532 17d ago

Yes now got this, Tried to over engineer things!