Ensure sorted order of mirrors in status page matches with JS
We had one sorting order in the backend, and another once the JS sorting routine kicked in. Match them so we aren't doing more on the client-side on initial display than we have to. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
021e7717e0
commit
4dcfaddff5
@ -43,8 +43,7 @@ def get_mirror_statuses(cutoff=default_cutoff):
|
||||
last_sync=Max('logs__last_sync'),
|
||||
last_check=Max('logs__check_time'),
|
||||
duration_avg=Avg('logs__duration'),
|
||||
duration_stddev=StdDev('logs__duration')
|
||||
).order_by('-last_sync', '-duration_avg')
|
||||
duration_stddev=StdDev('logs__duration'))
|
||||
|
||||
# The Django ORM makes it really hard to get actual average delay in the
|
||||
# above query, so run a seperate query for it and we will process the
|
||||
@ -112,7 +111,7 @@ def get_mirror_url_for_download(cutoff=default_cutoff):
|
||||
Max('check_time'), Max('last_sync'))
|
||||
if status_data['check_time__max'] is not None:
|
||||
min_check_time = status_data['check_time__max'] - timedelta(minutes=5)
|
||||
min_sync_time = status_data['last_sync__max'] - timedelta(minutes=30)
|
||||
min_sync_time = status_data['last_sync__max'] - timedelta(minutes=20)
|
||||
best_logs = MirrorLog.objects.filter(is_success=True,
|
||||
check_time__gte=min_check_time, last_sync__gte=min_sync_time,
|
||||
url__mirror__public=True, url__mirror__active=True,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import datetime
|
||||
from datetime import timedelta
|
||||
from operator import attrgetter, itemgetter
|
||||
|
||||
from django import forms
|
||||
@ -152,7 +152,7 @@ def mirror_details(request, name):
|
||||
|
||||
|
||||
def status(request):
|
||||
bad_timedelta = datetime.timedelta(days=3)
|
||||
bad_timedelta = timedelta(days=3)
|
||||
status_info = get_mirror_statuses()
|
||||
|
||||
urls = status_info['urls']
|
||||
@ -167,8 +167,8 @@ def status(request):
|
||||
|
||||
context = status_info.copy()
|
||||
context.update({
|
||||
'good_urls': good_urls,
|
||||
'bad_urls': bad_urls,
|
||||
'good_urls': sorted(good_urls, key=attrgetter('score')),
|
||||
'bad_urls': sorted(bad_urls, key=lambda u: u.delay or timedelta.max),
|
||||
'error_logs': get_mirror_errors(),
|
||||
})
|
||||
return direct_to_template(request, 'mirrors/status.html', context)
|
||||
@ -181,7 +181,7 @@ class MirrorStatusJSONEncoder(DjangoJSONEncoder):
|
||||
'delay', 'duration_avg', 'duration_stddev', 'score']
|
||||
|
||||
def default(self, obj):
|
||||
if isinstance(obj, datetime.timedelta):
|
||||
if isinstance(obj, timedelta):
|
||||
# always returned as integer seconds
|
||||
return obj.days * 24 * 3600 + obj.seconds
|
||||
if hasattr(obj, '__iter__'):
|
||||
|
Loading…
Reference in New Issue
Block a user