summaryrefslogtreecommitdiff
path: root/mirrors/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'mirrors/utils.py')
-rw-r--r--mirrors/utils.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/mirrors/utils.py b/mirrors/utils.py
index ddecb095..32fa3587 100644
--- a/mirrors/utils.py
+++ b/mirrors/utils.py
@@ -1,6 +1,7 @@
from datetime import timedelta
from django.db.models import Avg, Count, Max, Min, StdDev
+from django_countries.fields import Country
from main.utils import cache_function, utc_now
from .models import MirrorLog, MirrorProtocol, MirrorUrl
@@ -42,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
@@ -95,7 +95,8 @@ def get_mirror_errors(cutoff=default_cutoff):
).order_by('-last_occurred', '-error_count')
errors = list(errors)
for err in errors:
- err['country'] = err['url__country'] or err['url__mirror__country']
+ ctry_code = err['url__country'] or err['url__mirror__country']
+ err['country'] = Country(ctry_code)
return errors
@@ -110,20 +111,19 @@ 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,
- url__protocol__protocol__iexact='HTTP').order_by(
+ url__protocol__default=True).order_by(
'duration')[:1]
if best_logs:
return MirrorUrl.objects.get(id=best_logs[0].url_id)
mirror_urls = MirrorUrl.objects.filter(
- mirror__public=True, mirror__active=True,
- protocol__protocol__iexact='HTTP')
- # look first for an 'Any' URL, then fall back to any HTTP URL
- filtered_urls = mirror_urls.filter(mirror__country='Any')[:1]
+ mirror__public=True, mirror__active=True, protocol__default=True)
+ # look first for a country-agnostic URL, then fall back to any HTTP URL
+ filtered_urls = mirror_urls.filter(mirror__country='')[:1]
if not filtered_urls:
filtered_urls = mirror_urls[:1]
if not filtered_urls: