django-sortedm2m icon indicating copy to clipboard operation
django-sortedm2m copied to clipboard

Duplicated query in forms.py

Open nemesifier opened this issue 7 years ago • 0 comments

I have noticed a duplicated query while debugging openwisp2 generated by django-sortedm2m.

It seems that this line: https://github.com/gregmuellegger/django-sortedm2m/blob/bcb24c829576e14c416066b8018fc8a2dee58b7b/sortedm2m/forms.py#L52 Is evaluating the same queryset twice, hence querying 2 times the database for the same information.

The first query is generated when chain() is called, then when enumerate() is called. The current code is surely elegant and compact, but duplicated queries aren't equally nice.

I currently have no idea how to fix this. Any suggestion that may help me to send a patch?

nemesifier avatar Sep 08 '17 14:09 nemesifier