List Info

Thread: Re: ObjectPaginator Performance in Busy Sites




Re: ObjectPaginator Performance in Busy Sites
country flaguser name
United States
2007-08-31 14:25:51
There should be no problem at all (taken from the paginator
source
http://code.djangoproject.com/bro
wser/django/trunk/django/core/paginator.py#L39):
An queryset like Category.objects.all() would result in (see
above
link):
>>> from django.db import connection
>>> Category.objects.all()[5:10]
[<Category: Fleisch>, <Category: Vorspeise,
Snack>, <Category:
Aufstrich>, <Category: Suppe>, <Category:
Tip>]
which translates into the following sql:
>>> connection.queries[-1]
{'time': '0.007', 'sql': u'SELECT
`cookbook_category`.`id`,`cookbook_category`.`category`
FROM
`cookbook_category` LIMIT 5,5 '}

As you can see limit is used (as the queryset is not
executed and
sliced then...) and not all objects get fetched.

Hope this helps,
Florian Apolloner

On Aug 31, 9:11 pm, Sebastian Macias <sebast...sebastianmacias.com>
wrote:
> I'm building an app that requires pagination. I looked
at the
> official
> pagination documentation I found at:
>
> http://www.djangoproject.com/documentation/models/p
agination/
>
> I followed the tutorial and basically: paginator =
> ObjectPaginator(Article.objects.all(), 5) is where all
the "magic"
> happens.
>
> What I'm concerned about is that Article.objects.all()
will return a
> query_set with all of the records. If I have millions
of records it
> means the returned query_set will be huge and I'm
affraid performance
> will be poor in and very busy site.
>
> Should I be concerned about this? What are your
thoughs?
>
> Thanks,
>
> Sebastian Macias


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


Re: ObjectPaginator Performance in Busy Sites
user name
2007-08-31 14:32:16
On Aug 31, 9:11 pm, Sebastian Macias <sebast...sebastianmacias.com>
wrote:
> What I'm concerned about is that Article.objects.all()
will return a
> query_set with all of the records. If I have millions
of records it
> means the returned query_set will be huge and I'm
affraid performance
> will be poor in and very busy site.
>
> Should I be concerned about this? What are your
thoughs?

No, because the ObjectPaginator does only two queries: one
is a COUNT
to determine whether the specific page of the Paginator
being request
is valid (and to fill the "hits" variable), the
other retrieves only
the specific objects for the particular page.

If you're worried about "all()" returning millions
of objects, you
should read the documentation more carefully to see when
that's turned
into a database query and how -- I strongly suspect that you
skipped
over a very important part:

http://www.djangoproject.com/documentation/
db-api/#querysets-are-lazy


-- 
"Bureaucrat Conrad, you are technically correct -- the
best kind of correct."

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


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )