summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-10-10 20:17:55 -0500
committerDan McGee <dan@archlinux.org>2012-10-10 20:17:55 -0500
commitf0b7e73de61c03a5018ed352605e6329611448d2 (patch)
tree9fc2bfb970062599130cd6d8a73ed13f25231dd6
parentddb7f4825f8bf70142735a5ba2f7729ffe5d27c1 (diff)
Make mirror log time query a bit more efficient
We don't need the full mirror log objects; we just need a very small subset of values from them here to do the required math and object building. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--mirrors/utils.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/mirrors/utils.py b/mirrors/utils.py
index bf030d39..0a32b766 100644
--- a/mirrors/utils.py
+++ b/mirrors/utils.py
@@ -50,12 +50,14 @@ def get_mirror_statuses(cutoff=DEFAULT_CUTOFF):
# 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
# results here.
- times = MirrorLog.objects.filter(is_success=True, last_sync__isnull=False,
+ times = MirrorLog.objects.values_list(
+ 'url_id', 'check_time', 'last_sync').filter(
+ is_success=True, last_sync__isnull=False,
check_time__gte=cutoff_time)
delays = {}
- for log in times:
- delay = log.check_time - log.last_sync
- delays.setdefault(log.url_id, []).append(delay)
+ for url_id, check_time, last_sync in times:
+ delay = check_time - last_sync
+ delays.setdefault(url_id, []).append(delay)
if urls:
last_check = max([u.last_check for u in urls])