Web Images Videos Maps News Groups Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Optimizing queries
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Victor  
View profile  
 More options Nov 9, 4:06 am
From: Victor <psyco...@gmail.com>
Date: Sun, 8 Nov 2009 09:06:33 -0800 (PST)
Local: Mon, Nov 9 2009 4:06 am
Subject: Optimizing queries
Hi,

I'm trying to optimize some queries I'm making, but I'm not sure how
to do it.

 61             for t in items:
 62                 try:
 63                     t.price = t.user_item_rel_set.get
(user=u).payment_amount
 64                 except:
 65                     t.price = -1 * t.buyer_item_rel_set.get
(buyer=u).payment_amount
 66             return items
 67

user_item_rel_set is a m2m relationship between the User and Item
class.  For every item, I look back at its m2m relationship model and
retrieve payment_amount.  The only problem is, select_related()
doesn't grab the user_item_rel_set.all() when I query for the items
(where items=Item.objects.select_related().all() ).  Is there anything
I can do to speed this up? It's *very* slow.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tomasz Zieliński  
View profile  
 More options Nov 9, 6:06 pm
From: Tomasz Zieliński <tomasz.zielin...@pyconsultant.eu>
Date: Sun, 8 Nov 2009 23:06:34 -0800 (PST)
Local: Mon, Nov 9 2009 6:06 pm
Subject: Re: Optimizing queries
On 8 Lis, 18:06, Victor <psyco...@gmail.com> wrote:

> Hi,

> user_item_rel_set is a m2m relationship between the User and Item
> class.  For every item, I look back at its m2m relationship model and
> retrieve payment_amount.  The only problem is, select_related()
> doesn't grab the user_item_rel_set.all() when I query for the items
> (where items=Item.objects.select_related().all() ).  Is there anything
> I can do to speed this up? It's *very* slow.

I'm not sure what you're trying to do, but what about:

items_user = Item.objects.filter(user=u)
items_buyer = Item.objects.filter(buyer=u)

- and then do something with those lists?

--
Tomasz Zieliński
http://pyconsultant.eu


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google