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

Cluster TaggableManager is doing too much queries

Open marctc opened this issue 10 years ago • 5 comments
trafficstars

I'm using a ClusterTaggableManager on a Wagtail project that I'm currently developing. I realized that using this Manager it performs a huge amount of queries when rendering templates,

captura de 2015-08-25 14 35 04

while TaggableManager don't.

I've tried to replace get_queryset = get_query_set by get_queryset = _TaggableManager.get_query_set and it seems to work everything (I think) and don't perform that queries. I also saw that there is a comment in that function that begins with "FIXME". Why is this custom get_query_set method needed? Could be improved easily to not perform such amount of queries?

marctc avatar Aug 25 '15 12:08 marctc

If you bypass ClusterTaggableManager's get_query_set method, it won't be able to pick up local changes to the tag field that aren't committed to the database. For Wagtail, this means that if you preview a page with a tag field, or view a draft version of it while a live version exists, it will show you the tags from the live version of the page.

gasman avatar Aug 25 '15 13:08 gasman

Ok, those are the scenarios that I didn't tried (I haven't thought about it, sorry). So, are you telling me that those amount of queries are needed in order to ClusterTaggableManager works as expected, right?

marctc avatar Aug 25 '15 13:08 marctc

Not at all - I'm sure that method could be optimised to reduce the number of queries. It can't be eliminated entirely, though.

gasman avatar Aug 25 '15 13:08 gasman

Hi @marctc ,

I'm facing the same issue. Were you able to optimize the performance?

cefeboru avatar Sep 04 '17 19:09 cefeboru

Nope. I fact i didn't tried to optimize TBH

marctc avatar Sep 04 '17 20:09 marctc