Convert mirror status tables to Jinja2

Yay for way improved performance. Local testing showed render times
going from 265 ms to 135 ms.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2014-11-08 14:00:06 -06:00
parent eb7172cd4d
commit 713ab837ba
6 changed files with 57 additions and 39 deletions

View File

@ -1,3 +1,4 @@
from datetime import timedelta
from django_jinja import library
from markupsafe import Markup
@ -22,10 +23,31 @@ def duration(value):
return '%d:%02d' % (hrs, mins)
@library.filter
def hours(value):
if not value and type(value) != timedelta:
return u''
# does not take microseconds into account
total_secs = value.seconds + value.days * 24 * 3600
mins = total_secs // 60
hrs, mins = divmod(mins, 60)
if hrs == 1:
return '%d hour' % hrs
return '%d hours' % hrs
@library.filter
def floatvalue(value, arg=2):
if value is None:
return u''
return '%.*f' % (arg, value)
@library.filter
def percentage(value, arg=1):
if not value and type(value) != float:
return u''
new_val = value * 100.0
return '%.*f%%' % (arg, new_val)
# vim: set ts=4 sw=4 et:

View File

@ -1,5 +1,3 @@
{% load cycle from future %}
{% load flags mirror_status %}
<table id="errorlog_mirrors" class="results">
<thead>
<tr>
@ -12,12 +10,12 @@
</tr>
</thead>
<tbody>
{% for log in error_logs %}<tr class="{% cycle 'odd' 'even' %}">
{% for log in error_logs %}<tr class="{{ loop.cycle('odd', 'even') }}">
<td>{{ log.url__url }}</td>
<td>{{ log.url__protocol__protocol }}</td>
<td class="country">{% country_flag log.country %}{{ log.country.name }}</td>
<td class="country">{{ country_flag(log.country) }}{{ log.country.name }}</td>
<td class="wrap">{{ log.error|linebreaksbr }}</td>
<td>{{ log.last_occurred|date:'Y-m-d H:i' }}</td>
<td>{{ log.last_occurred|date('Y-m-d H:i') }}</td>
<td>{{ log.error_count }}</td>
</tr>{% endfor %}
</tbody>

View File

@ -132,7 +132,7 @@ <h3>Available URLs</h3>
</table>
<h3>Error Log</h3>
{% include "mirrors/error_table.html" %}
{% include "mirrors/error_table.html.jinja" %}
</div>
<div class="box">

View File

@ -60,18 +60,18 @@ <h2>Mirror Status{% if tier != None %} - Tier {{ tier }}{% endif %}</h2>
<a name="outofsync" id="outofsync"></a>
<h3>Out of Sync Mirrors</h3>
{% with urls=bad_urls table_id='outofsync_mirrors' %}
{% include "mirrors/status_table.html" %}
{% include "mirrors/status_table.html.jinja" %}
{% endwith %}
<a name="successful" id="successful"></a>
<h3>Successfully Syncing Mirrors</h3>
{% with urls=good_urls table_id='successful_mirrors' %}
{% include "mirrors/status_table.html" %}
{% include "mirrors/status_table.html.jinja" %}
{% endwith %}
<a name="errorlog" id="errorlog"></a>
<h3>Mirror Syncing Error Log</h3>
{% include "mirrors/error_table.html" %}
{% include "mirrors/error_table.html.jinja" %}
</div>
{% endblock %}

View File

@ -1,30 +0,0 @@
{% load cycle from future %}
{% load flags mirror_status %}
<table id="{{ table_id }}" class="results">
<thead>
<tr>
<th>Mirror URL</th>
<th>Protocol</th>
<th>Country</th>
<th>Completion %</th>
<th>μ Delay (hh:mm)</th>
<th>μ Duration (s)</th>
<th>σ Duration (s)</th>
<th>Mirror Score</th>
<th></th>
</tr>
</thead>
<tbody>
{% for m_url in urls %}<tr class="{% cycle 'odd' 'even' %}">
<td>{{ m_url.url }}</td>
<td>{{ m_url.protocol }}</td>
<td class="country">{% country_flag m_url.country %}{{ m_url.country.name }}</td>
<td>{{ m_url.completion_pct|percentage:1 }}</td>
<td>{{ m_url.delay|duration|default:'unknown' }}</td>
<td>{{ m_url.duration_avg|floatvalue:2 }}</td>
<td>{{ m_url.duration_stddev|floatvalue:2 }}</td>
<td>{{ m_url.score|floatvalue:1|default:'∞' }}</td>
<td><a href="{{ m_url.get_absolute_url }}">details</a></td>
</tr>{% endfor %}
</tbody>
</table>

View File

@ -0,0 +1,28 @@
<table id="{{ table_id }}" class="results">
<thead>
<tr>
<th>Mirror URL</th>
<th>Protocol</th>
<th>Country</th>
<th>Completion %</th>
<th>μ Delay (hh:mm)</th>
<th>μ Duration (s)</th>
<th>σ Duration (s)</th>
<th>Mirror Score</th>
<th></th>
</tr>
</thead>
<tbody>
{% for m_url in urls %}<tr class="{{ loop.cycle('odd', 'even') }}">
<td>{{ m_url.url }}</td>
<td>{{ m_url.protocol }}</td>
<td class="country">{{ country_flag(m_url.country) }}{{ m_url.country.name }}</td>
<td>{{ m_url.completion_pct|percentage(1) }}</td>
<td>{{ m_url.delay|duration|default('unknown') }}</td>
<td>{{ m_url.duration_avg|floatvalue(2) }}</td>
<td>{{ m_url.duration_stddev|floatvalue(2) }}</td>
<td>{{ m_url.score|floatvalue(1)|default('∞') }}</td>
<td><a href="{{ m_url.get_absolute_url() }}">details</a></td>
</tr>{% endfor %}
</tbody>
</table>