Thank you Damanjeet

On Sunday, July 19, 2020 at 3:32:02 AM UTC-4, Damanjeet Singh wrote:
>
> Hello ,
>
> Prefetch_related can be helpful, see doc 
>
>
>
> https://docs.djangoproject.com/en/3.0/ref/models/querysets/#prefetch-related
>
> Regards,
> Damanjeet
>
>
>
> On Sun, 19 Jul 2020, 04:39 karthik challa, <challa...@gmail.com 
> <javascript:>> wrote:
>
>> Hi Experts,
>>
>> I am trying to execute the below query and the query is taking more than 
>> 5 minutes.
>>
>> Here are the details
>>
>> Model.py
>>
>> class Url(models.Model):
>>  subdomain = models.ForeignKey(Subdomain, null=True, blank=True, 
>> related_name='url_subdomain', on_delete=models.SET_NULL,db_index=True)
>>  full_url = models.CharField(max_length=1000, unique=True, db_index=True)
>>  class Meta:
>>  ordering = ['full_url']
>>
>>  def __str__(self):
>>  return self.full_url
>>
>> 1>Django query ORM 
>>
>> subdomains = Subdomain.objects.all().annotate(numItems=Count(
>> 'url_subdomain')).order_by('name')
>>
>> 2>SQL Query 
>>
>> SELECT "urls_subdomain"."id", "urls_subdomain"."created_at", 
>> "urls_subdomain"."name", COUNT("urls_url"."id") AS "numItems" 
>> <http://localhost:8000/urls/search/#> FROM "urls_subdomain" LEFT OUTER 
>> JOIN "urls_url" ON ("urls_subdomain"."id" = "urls_url"."subdomain_id") 
>> GROUP BY "urls_subdomain"."id" ORDER BY "urls_subdomain"."name" ASC
>>
>> 3>Templates
>>
>> {% if subdomains %}
>>      <div id="step-filter-tag" class="mb4">
>>          <div class="b mb3">Subdomain</div>
>>              <div class="overflow-auto" style="max-height: 16rem;">
>>                  {% for item in subdomains %}
>>                      item
>>                  {% endfor %}
>>              </div>
>>      </div>
>>
>>  {% endif %}
>>
>> Please let me know how can i optimize the preformance Thanks & Regards,
>> Karthik
>>
>> -- 
>> 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 django...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/83c9f9a3-1a14-4729-b2cb-3abeb06a8b2fo%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/83c9f9a3-1a14-4729-b2cb-3abeb06a8b2fo%40googlegroups.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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/19cf375d-97ae-47ff-80cc-08c60174370bo%40googlegroups.com.

Reply via email to