Hi guys,
I'm trying to optimize one of my views that is doing a rather (naive?)
query like this:
...
post_stream = Post.objects.filter(poster=some_user)
for other_user in other_user_queryset:
post_stream = post_stream | Post.objects.filter(poster=other_user)
...
The idea is that I want to display a post stream of lots of different
user's aggregated posts in one place, intermixed. by date (I've left
out the order_by filter).
The ORM generates a SQL query for each of the additional piped OR
queries (this becomes a large number very quickly!). I was wondering
if there were any methods available to combine this into a single
query so as to stop hitting the database? I don't really want to
resort to writing raw SQL, as I imagine this is a very common
scenario, but if this is the only way, then I'll give it a try! I've
added select_related to both of the object managers which helps
somewhat, but not totally.
Also, I'm a bit of a beginner at SQL optimisation, so if I've made an
obvious newbie error - please let me know!
Thanks for your help,
Mike.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---