Hi all
Using django-pagination, I encounter some serious performance problems
related to django-pagination. Request for every page triggers sql query
returning all Post instances, here's  detailed description of my problem:

My model Is:
class Post(models.Model):
        group           = models.ForeignKey(Group, verbose_name='Grupa',)
        messageid       = models.CharField("Message-Id", max_length=512)
        subject         = models.CharField("Subject", max_length=512)
        author          = models.ForeignKey(Author, verbose_name="Autor")
        posting_date    = models.DateTimeField("NNTP-Posting-Date",
blank=True)
        date_added      = models.DateTimeField("Dodany", auto_now_add=True)

        def __unicode__(self):
                return "[%s] %s" % (self.group, self.messageid)
        class Meta:
                ordering=['-posting_date']


and urls:
posts_dict={
        'queryset': Post.objects.all(),
        'template_name': 'galgather/posts_archive.html',
        'allow_empty':True,
        'template_object_name':'posts',
        }
[...]
url(r'/$', object_list, dict(posts_dict), 'posts_archive',),
[...]

I want to paginate over Posts.objects.all(), so in my template i use:
{% autopaginate posts_list 20  %}
{% paginate %}
{% for post in posts_list %}
[...]
{% endfor %}

The problem is that every request for each page generates sql queries
fetching all objects, than django asks about Post count.
Queries looks like that:

SELECT "galgather_post"."id", "galgather_post"."group_id",
"galgather_post"."messageid", "galgather_post"."subject",
"galgather_post"."author_id", "galgather_post"."posting_date",
"galgather_post"."date_added" FROM "galgather_post" ORDER BY
"galgather_post"."posting_date" DESC

SELECT COUNT(*) FROM "galgather_post"


>>> Post.objects.count()
18145L

so... looks like everytime I need 20 Post items my database is hit by
query returning all records... I find it a big overhead, and my app
suffers from that...

I've read:
http://code.google.com/p/django-pagination/issues/detail?id=15
and
http://code.google.com/p/django-pagination/source/detail?r=27
and wandering if its normal behaviour? If not, what could the cause of
that nasty problem?

My python knowledge however still improoving, but still isn't sufficient
to quick analyze django code.

Thanks in advance

-- 
Bartek
spamtrap: http://sq9mev.info/spamtrap.html



--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to