Monday, March 28, 2011

Re: Slow query. Any way to speed things up?

On Mon, Mar 28, 2011 at 7:52 AM, Fabian Büchler
<fabian.buechler@gmail.com> wrote:
>
> Events have an EventOnlineManager with a "to_expire" method which should select all Events with status=online and EventDates associated which date < today.
>
>> class EventOnlineManager(models.Manager):
>>
>>     def get_query_set(self):
>>         return (super(EventOnlineManager, self).get_query_set()
>>                     .filter(status=Event.STATUS_ONLINE))
>>
>>     @property
>>     def to_expire(self):
>>         today = datetime.date.today()
>>         return (self.annotate(eventdate_max=models.Max('eventdate__date'))
>>                     .filter(eventdate_max__lt=today))

I guess you have reasons to allow several EventDates per Event (if
not, they should be a single table). my first attempt would be to
add an (event, date) index to EventDate. can you add an
ordering=('event','date') ?

--
Javier

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment