etianen / django-watson

Full-text multi-table search application for Django. Easy to install and use, with good performance.
BSD 3-Clause "New" or "Revised" License
1.2k stars 130 forks source link

prefetch related #181

Open robslotboom opened 7 years ago

robslotboom commented 7 years ago

Maybe interesting.

To limit the amount of queries you can do the following in the search view:

self.object_list = self.get_queryset().prefetch_related('object')

Cheers,

Robert

robslotboom commented 7 years ago

Unfortunately this is only supported if the query is restricted to one ContentType...

etianen commented 7 years ago

Unfortunately, this caused major bugs with Django, and so had to be taken out.

I'll leave open for now, however, as it should go back into once Django has released a few more versions and I can drop support for the broken ones.

valentijnscholten commented 4 years ago

I'm using prefetch with watson search and so far it works fine.

products = watson.search(clean_query, models=(Product,)).prefetch_related('object', 'object__engagement_set')
etianen commented 4 years ago

Excellent. I'd take a MR that puts this feature back in.

robslotboom commented 4 years ago

2016...

etianen commented 4 years ago

Pardon?

robslotboom commented 4 years ago

That’s 4 years back :-D

valentijnscholten commented 4 years ago

Still I think it only works if you have only 1 model / content_type in the results and you have to know which one up front. Unless you only want to prefetch object, which is in itself already a performance improvement if you access it in your search results.