optimize database query on overview page

This commit is contained in:
Fabian Weisshaar 2015-12-30 11:51:39 +01:00
parent 58f7237654
commit 4717da5ae6
2 changed files with 27 additions and 19 deletions

View File

@ -50,27 +50,31 @@
<br><span class="label label-warning">{% trans "Abuse" %}</span>
{% endif %}
</td>
<td>{{ host.get_ipv4|default_if_none:_("none")}}
{% with ipv4=host.get_ipv4 %}
<td>{{ ipv4|default_if_none:_("none")}}
<br>
{% if host.last_update_ipv4 and host.get_ipv4 %}
({{ host.last_update_ipv4|naturaltime }},
{% if not host.tls_update_ipv4 %}
<span class="label label-warning">{% trans "no" %} {% else %}
<span class="label label-success">{% endif %}{% trans "TLS" %}</span>)
{% elif host.get_ipv4 %}
({% trans "unknown" %})
{% if host.last_update_ipv4 and ipv4 %}
({{ host.last_update_ipv4|naturaltime }},
{% if not host.tls_update_ipv4 %}
<span class="label label-warning">{% trans "no" %} {% else %}
<span class="label label-success">{% endif %}{% trans "TLS" %}</span>)
{% elif ipv4 %}
({% trans "unknown" %})
{% endif %}
{% endwith %}
</td>
<td>{{ host.get_ipv6|default_if_none:_("none") }}
{% with ipv6=host.get_ipv6 %}
<td>{{ ipv6|default_if_none:_("none") }}
<br>
{% if host.last_update_ipv6 and host.get_ipv6 %}
({{ host.last_update_ipv6|naturaltime }},
{% if not host.tls_update_ipv6 %}
<span class="label label-warning">{% trans "no" %} {% else %}
<span class="label label-success">{% endif %}{% trans "TLS" %}</span>)
{% elif host.get_ipv6 %}
({% trans "unknown" %})
{% if host.last_update_ipv6 and ipv6 %}
({{ host.last_update_ipv6|naturaltime }},
{% if not host.tls_update_ipv6 %}
<span class="label label-warning">{% trans "no" %} {% else %}
<span class="label label-success">{% endif %}{% trans "TLS" %}</span>)
{% elif ipv6 %}
({% trans "unknown" %})
{% endif %}
{% endwith %}
</td>
</tr>
{% empty %}

View File

@ -191,11 +191,15 @@ class OverviewView(TemplateView):
def get_context_data(self, **kwargs):
context = super(OverviewView, self).get_context_data(**kwargs)
context['nav_overview'] = True
context['hosts'] = Host.objects.filter(created_by=self.request.user)
context['hosts'] = Host.objects.filter(created_by=self.request.user).select_related("domain")\
.only("name", "comment", "available", "client_faults", "server_faults", "abuse_blocked", "abuse",
"last_update_ipv4", "tls_update_ipv4", "last_update_ipv6", "tls_update_ipv6", "domain__name")
context['your_domains'] = Domain.objects.filter(
created_by=self.request.user)
created_by=self.request.user).select_related("created_by__username")\
.only("name", "public", "available", "comment", "created_by__username")
context['public_domains'] = Domain.objects.filter(
public=True).exclude(created_by=self.request.user)
public=True).exclude(created_by=self.request.user).select_related("created_by")\
.only("name", "public", "available", "comment", "created_by__username")
return context