On Fri, 2007-03-09 at 15:20 +0000, [EMAIL PROTECTED] wrote: > I was trying to figure out how exactly caching worked with the query > sets... > > If I was running three different queries against the same table like > below, I know it hits the DB each time: > > objects = MyObject.objects.fillter(object_name="value") > # some code here > > objects = MyObject.objects.fillter(object_name="value2") > # some code here > > objects = MyObject.objects.fillter(object_name="value3") > # some code here > > > If I instead did this, would it reduce DB hits..or does it still hit > the DB for the Query each time? > > allobjects = MyObject.objects.all() > objects = allobjects.fillter(object_name="value") > # some code here > > objects = allobjects.fillter(object_name="value2") > # some code here > > objects = allobjects.fillter(object_name="value3") > # some code here > > Thanks for any info! Just trying to optimize things.
If you are accessing 'objects' each time, then yes. Basically, a QuerySet does not do anything (database-wise) until you try to access one of the result values. At that point it runs the SQL query it is representing against the database and starts to retrieve the results as you request them. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

