Formsets

24 views
Skip to first unread message

Steven Smith

unread,
Feb 5, 2022, 3:27:10 PM2/5/22
to Django users
Hello all!   

I find formsets wildly useful...but very difficult to architect.  I have them working...But I am running into a commonly documented problem...They are slow as you build up the number of fields and queries.  Are there any general tips that can be used or share on how to improve this issue?  I have tried all of the commonly prescribed solutions...select_related...prefetch_related...etc...But nothing seems to help.  

I realize that Queries take time....but I'm just trying to see if there is a way to streamline them a bit.  It seems to me that formsets use a lot of queries depending on the amount of data and that's the trade off. 

Again thanks for any thoughts or comments.

Steve

Steven Mapes

unread,
Feb 6, 2022, 12:47:26 PM2/6/22
to Django users
For me using select_related, prefetch_related and defer generally soft the issues. If that's still too slow then, if possible, you could look at using caching the queryset(s) you need the values. Have you run debug toolbar on the page to check what queries are running?

Steve Smith

unread,
Feb 6, 2022, 6:14:26 PM2/6/22
to Django users
HI Steve!  

Thanks for the reply.  I have tried select related and prefetch related....but didn't know about defer....will look into...my current formset scenario is 440ish queries and it takes about 19 seconds to load.  Some have suggested Celery and RabbitMQ and other alternatives which I'm not familiar with.  I need to explore those things further.  I have used the debug toolbar as well....it shows me that there are lots of duplicate queries...but I'm unclear on how to go about fixing them...as the select related and prefetch hasn't seemed to help either.  

I'm using class based views with formsets and just kind of at a loss right now as to if there is anything that can be done to speed up these queries.  I opened up a SO on the issue...and got some suggestions on how to go about improving my dictionary look up...but after trying some of those suggestions the performance issue remains.  

Thanks again for taking the time to respond.

Steve

From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Steven Mapes <st...@jigsawtech.co.uk>
Sent: Sunday, February 6, 2022 11:47 AM
To: Django users <django...@googlegroups.com>
Subject: Re: Formsets
 
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6513c105-8151-4c7a-8fd2-e692d5c5dcb5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages