Budi Hermansyah no, but I think i can improve the queries but I don't know how: / the debug toolbar show many many queries to the database * (44 queries including 34 duplicates ) i don't know duplicates*
On Sat, Jul 11, 2020 at 10:58 AM damanjeet kaur <[email protected]> wrote: > {% for news7 in newscat7 %} > {{news7.name <http://news.name/>}} > {{news7.date|date:'Y-m-d'}} > {{news7.body|safe|truncatewords:20}} > {{news7.category.all.0}} > <a href="{{news7.get_absolute_url}}">Read More</a> > {% endfor %} > > > > On Sat, Jul 11, 2020 at 10:46 AM carlos <[email protected]> wrote: > >> Hi, i need any advice for performance queries >> i have a model name Post >> post have m2m categories and fk author >> >> the index page show 7 categories in separated row >> i try performance >> this example >> queryset_global = >> Post.objects.filter(status__contains='publish').prefetch_related('category').select_related('author') >> then i make 7 queries for 7 categories show in index page. >> >> newscat1 >> = >> queryset_global.filter(category__slug__contains="cat1_name").order_by('-date')[:5] >> newscat2 >> = >> queryset_global.filter(category__slug__contains="cat2_name").order_by('-date')[:5] >> newscat3 >> = >> queryset_global.filter(category__slug__contains="cat3_name").order_by('-date')[:5] >> newscat4 >> = >> queryset_global.filter(category__slug__contains="cat4_name").order_by('-date')[:5] >> newscat5 >> = >> queryset_global.filter(category__slug__contains="cat5_name").order_by('-date')[:5] >> newscat6 >> = >> queryset_global.filter(category__slug__contains="cat6_name").order_by('-date')[:5] >> newscat7 >> = >> queryset_global.filter(category__slug__contains="cat7_name").order_by('-date')[:5] >> >> i retrieve 35 post for show in index page >> >> *according debug toolbar this produce SQL* >> *2599.59 ms (44 queries including 34 duplicates )* >> >> Why? >> >> but when i loop in template index.html >> {% for news1 in newscat1 %} >> {{news.name}} >> {{newa.date|date:'Y-m-d'}} >> {{news.body|safe|truncatewords:20}} >> {{news.category.all.0}} >> <a href="{{news.get_absolute_url}}">Read More</a> >> {% endfor %} >> ... >> this repeat in the template 7 time >> ... >> {% for news7 in newscat7 %} >> {{news.name}} >> {{newa.date|date:'Y-m-d'}} >> {{news.body|safe|truncatewords:20}} >> {{news.category.all.0}} >> <a href="{{news.get_absolute_url}}">Read More</a> >> {% endfor %} >> >> >> *according debug toolbar this produce SQL* >> *3463.65 ms (86 queries including 77 duplicates )* >> >> this is incredible it doubles the amount of queries to the db that may be >> happening? >> >> i need some ideas or tips >> >> Cheers >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAM-7rO1nzzqWf_cpQOrjYwQmxkd77H0AJ8W03FS%3D%2BoA3gEE4zg%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAM-7rO1nzzqWf_cpQOrjYwQmxkd77H0AJ8W03FS%3D%2BoA3gEE4zg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAJTCr6E2Vk_VMuRMBpUftmGLnyCbWUq1Dkq6ZN2ttn0xmody3Q%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAJTCr6E2Vk_VMuRMBpUftmGLnyCbWUq1Dkq6ZN2ttn0xmody3Q%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- att. Carlos Rocha -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM-7rO1Jc_Dv4vOq4B_HJXHPioorn_cX_cmcJJCe1ouTC56rzw%40mail.gmail.com.

