optimize provider views

main
eric 2023-09-06 17:26:35 -04:00
parent 8836372d19
commit 0a3a1ca6d4
3 changed files with 9 additions and 11 deletions

View File

@ -22,7 +22,7 @@ Link Checking for
{% for code in codes %}
<tr {% if code.recent_check__return_code != 200 %} style="color:red"{% endif %}>
<td> {{ code.recent_check__return_code }} </td>
<td> <a href="#code{{ code.recent_check__return_code }}">{{ code.count }}</a>
<td> <a href="#code{{ code.recent_check__return_code }}">{{ code.recent_check__return_code__count }}</a>
<td><a href="{% url 'fixing' %}#{{ code.recent_check__return_code }}">how to fix</a></td>
</tr>
{% empty %}
@ -36,7 +36,7 @@ Link Checking for
{% with code=codeobj.recent_check__return_code %}
<h3{% if code != 200 %} style="color:red"{% endif %} id="code{{ code }}"> {{ code }}</h3>
{% for link in codeobj.links %}
{% with title=link.items.all.0.title %}
{% with title=link.title %}
{% ifchanged title %}<div class='itemtitle'>{{ title }}</div>{% endifchanged %}
<div class='itemlink'><a href="{{ link.url }}">{{ link.url }}</a></div>

View File

@ -11,10 +11,10 @@
<h2>
DOAB Link Checking by Server Hostname
</h2>
<p>(number of links checked in parentheses)
<ul>
{% for provider in provider_list %}
<li><a href="{% url 'provider' provider.provider %}">{{provider.provider}}</a> ({{provider.link_count}})</li>
<li><a href="{% url 'provider' provider.provider %}">{{provider.provider}}</a> ({{provider.provider__count}})</li>
{% endfor %}
</ul>
</div>

View File

@ -1,7 +1,7 @@
"""doab_check views
"""
from django.db.models import Count, OuterRef, Subquery
from django.db.models import Count, F
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
@ -46,9 +46,8 @@ class ProvidersView(generic.TemplateView):
template_name = 'providers.html'
def get_context_data(self, **kwargs):
providers = Link.objects.order_by('provider').values('provider').distinct()
for provider in providers:
provider['link_count'] = Link.objects.filter(provider=provider['provider']).count()
providers = Link.objects.order_by('provider').filter(live=True, recent_check__isnull=False,
).values('provider').distinct().annotate(Count('provider'))
return {'provider_list': providers}
@ -61,12 +60,11 @@ class ProviderView(generic.TemplateView):
provider_links = Link.objects.filter(provider=prov, live=True, recent_check__isnull=False)
provider['link_count'] = provider_links.count()
codes = provider_links.order_by('-recent_check__return_code').values(
'recent_check__return_code').distinct()
'recent_check__return_code').distinct().annotate(Count('recent_check__return_code'))
for code in codes:
code['links'] = provider_links.filter(live=True,
recent_check__return_code=code['recent_check__return_code'],
).order_by('items__title')
code['count'] = code['links'].count()
).order_by('items__title').annotate(title=F('items__title'))
code['links'] = code['links'][:1000]
return {'provider': provider,