From bdfa22500f47fcfa0f40de14424c25792995c9e9 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 14 Dec 2013 17:10:52 -0600 Subject: Use stable parameters for cacheable function It doesn't do much good to mark a function as cacheable if we call it every single time with different arguments due to using the current date and time. Fix it by passing the offset in instead. Signed-off-by: Dan McGee --- mirrors/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mirrors') diff --git a/mirrors/utils.py b/mirrors/utils.py index 9f40bca6..0dd26ae0 100644 --- a/mirrors/utils.py +++ b/mirrors/utils.py @@ -22,7 +22,8 @@ def dictfetchall(cursor): ] @cache_function(178) -def status_data(cutoff_time, mirror_id=None): +def status_data(cutoff=DEFAULT_CUTOFF, mirror_id=None): + cutoff_time = now() - cutoff if mirror_id is not None: params = [cutoff_time, mirror_id] mirror_where = 'AND u.mirror_id = %s' @@ -125,7 +126,7 @@ def get_mirror_statuses(cutoff=DEFAULT_CUTOFF, mirror_id=None, show_all=False): valid_urls = valid_urls.filter(active=True, mirror__active=True, mirror__public=True) - url_data = status_data(cutoff_time, mirror_id) + url_data = status_data(cutoff, mirror_id) urls = MirrorUrl.objects.select_related('mirror', 'protocol').filter( id__in=valid_urls).order_by('mirror__id', 'url') -- cgit v1.2.3-54-g00ecf From 3c7b02753a4f742eeb66b8deea2fc3f179b87b8e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 15 Dec 2013 13:21:04 -0600 Subject: Add delay function to MirrorLog model Signed-off-by: Dan McGee --- mirrors/models.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'mirrors') diff --git a/mirrors/models.py b/mirrors/models.py index 47e2051b..d2c64c51 100644 --- a/mirrors/models.py +++ b/mirrors/models.py @@ -1,3 +1,4 @@ +from datetime import timedelta import socket from urlparse import urlparse @@ -159,6 +160,12 @@ class MirrorLog(models.Model): is_success = models.BooleanField(default=True) error = models.TextField(blank=True, default='') + def delay(self): + # sanity check, this shouldn't happen + if self.check_time < self.last_sync: + return timedelta() + return self.check_time - self.last_sync + def __unicode__(self): return "Check of %s at %s" % (self.url.url, self.check_time) -- cgit v1.2.3-54-g00ecf From 79aef280ddf0c704fd40d0077822a8ff7548437e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 15 Dec 2013 13:22:41 -0600 Subject: Add mirror URL details page This will allow those that care about mirrors to zoom into URL-level details for each mirror and examine the individual check results. Signed-off-by: Dan McGee --- mirrors/models.py | 2 + mirrors/urls.py | 1 + mirrors/views.py | 19 ++++++++ templates/mirrors/mirror_details.html | 8 +++- templates/mirrors/url_details.html | 89 +++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 templates/mirrors/url_details.html (limited to 'mirrors') diff --git a/mirrors/models.py b/mirrors/models.py index d2c64c51..57664562 100644 --- a/mirrors/models.py +++ b/mirrors/models.py @@ -161,6 +161,8 @@ class MirrorLog(models.Model): error = models.TextField(blank=True, default='') def delay(self): + if self.last_sync is None: + return None # sanity check, this shouldn't happen if self.check_time < self.last_sync: return timedelta() diff --git a/mirrors/urls.py b/mirrors/urls.py index 7cf76aa1..b1054380 100644 --- a/mirrors/urls.py +++ b/mirrors/urls.py @@ -9,6 +9,7 @@ (r'^locations/json/$', 'locations_json', {}, 'mirror-locations-json'), (r'^(?P[\.\-\w]+)/$', 'mirror_details'), (r'^(?P[\.\-\w]+)/json/$', 'mirror_details_json'), + (r'^(?P[\.\-\w]+)/(?P\d+)/$', 'url_details'), ) # vim: set ts=4 sw=4 et: diff --git a/mirrors/views.py b/mirrors/views.py index 9e05e5fc..b2e75b25 100644 --- a/mirrors/views.py +++ b/mirrors/views.py @@ -186,6 +186,7 @@ def mirror_details(request, name): } return render(request, 'mirrors/mirror_details.html', context) + def mirror_details_json(request, name): authorized = request.user.is_authenticated() mirror = get_object_or_404(Mirror, name=name) @@ -199,6 +200,24 @@ def mirror_details_json(request, name): return response +def url_details(request, name, url_id): + url = get_object_or_404(MirrorUrl, id=url_id, mirror__name=name) + mirror = url.mirror + authorized = request.user.is_authenticated() + if not authorized and \ + (not mirror.public or not mirror.active or not url.active): + raise Http404 + error_cutoff = timedelta(days=7) + cutoff_time = now() - error_cutoff + logs = MirrorLog.objects.filter(url=url, check_time__gte=cutoff_time).order_by('-check_time') + + context = { + 'url': url, + 'logs': logs, + } + return render(request, 'mirrors/url_details.html', context) + + def status(request, tier=None): if tier is not None: tier = int(tier) diff --git a/templates/mirrors/mirror_details.html b/templates/mirrors/mirror_details.html index aa0a9648..665ad805 100644 --- a/templates/mirrors/mirror_details.html +++ b/templates/mirrors/mirror_details.html @@ -41,6 +41,10 @@

Mirror Details: {{ mirror.name }}

Active: {{ mirror.active|yesno|capfirst }} + + Created: + {{ mirror.created }} + Rsync IPs: {{mirror.rsync_ips.all|join:', '}} @@ -99,7 +103,8 @@

Available URLs

μ Delay (hh:mm) μ Duration (secs) σ Duration (secs) - Mirror Score + Score + Details @@ -116,6 +121,7 @@

Available URLs

{{ m_url.duration_avg|floatvalue:2 }} {{ m_url.duration_stddev|floatvalue:2 }} {{ m_url.score|floatvalue:1|default:'∞' }} + Details {% endfor %} diff --git a/templates/mirrors/url_details.html b/templates/mirrors/url_details.html new file mode 100644 index 00000000..0b9d2916 --- /dev/null +++ b/templates/mirrors/url_details.html @@ -0,0 +1,89 @@ +{% extends "base.html" %} +{% load cycle from future %} +{% load static from staticfiles %} +{% load mirror_status %} +{% load flags %} + +{% block title %}Arch Linux - {{ url.url }} - URL Details{% endblock %} + +{% block head %}{% endblock %} + +{% block content %} +
+

URL Details: {{ url.url }}

+ + + + + + + + + + + + + + + + + + + + + + + {% if user.is_authenticated %} + + + + + + + + + {% endif %} +
URL:{{ url.url }}
Protocol:{{ url.protocol }}
Country:{% country_flag url.country %}{{ url.country.name }}
IPv4:{{ url.has_ipv4|yesno|capfirst }}
IPv6:{{ url.has_ipv6|yesno|capfirst }}
Active:{{ url.active|yesno|capfirst }}
Created:{{ url.created }}
+ +

Check Logs

+ + + + + + + + + + + + + + + + {% for log in logs %} + + + + + + + + + {% endfor %} + +
Check TimeCheck LocationCheck IPLast SyncDelay (hh:mm)Duration (secs)Success?Error Message
{{ log.check_time|date:'Y-m-d H:i' }}{% country_flag log.location.country %}{{ log.location.country.name }}{{ log.location.source_ip }}{{ log.last_sync|date:'Y-m-d H:i' }}{{ log.delay|duration }}{{ log.duration|floatvalue }}{{ log.is_success|yesno|capfirst }}{{ log.error|linebreaksbr }}
+
+{% endblock %} + +{% block script_block %} +{% load cdn %}{% jquery %}{% jquery_tablesorter %} + + +{% endblock %} -- cgit v1.2.3-54-g00ecf From 77a45dc7bc6f0badb45ec043e85f1b542c52792e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 15 Dec 2013 13:33:50 -0600 Subject: Use select_related() in new mirror URL details view Signed-off-by: Dan McGee --- mirrors/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'mirrors') diff --git a/mirrors/views.py b/mirrors/views.py index b2e75b25..34336165 100644 --- a/mirrors/views.py +++ b/mirrors/views.py @@ -201,7 +201,8 @@ def mirror_details_json(request, name): def url_details(request, name, url_id): - url = get_object_or_404(MirrorUrl, id=url_id, mirror__name=name) + url = get_object_or_404(MirrorUrl.objects.select_related(), + id=url_id, mirror__name=name) mirror = url.mirror authorized = request.user.is_authenticated() if not authorized and \ @@ -209,7 +210,8 @@ def url_details(request, name, url_id): raise Http404 error_cutoff = timedelta(days=7) cutoff_time = now() - error_cutoff - logs = MirrorLog.objects.filter(url=url, check_time__gte=cutoff_time).order_by('-check_time') + logs = MirrorLog.objects.select_related('location').filter( + url=url, check_time__gte=cutoff_time).order_by('-check_time') context = { 'url': url, -- cgit v1.2.3-54-g00ecf