summaryrefslogtreecommitdiff
path: root/mirrors/views.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2014-10-21 09:10:28 -0500
committerDan McGee <dan@archlinux.org>2014-10-21 09:40:14 -0500
commitee6bf2782068b917232c71189aea0011b47e876d (patch)
treeca3457fa7dbe6acde913f416efa2813e0b9ad16f /mirrors/views.py
parentf9f8683799ef96904a7165adcfdeb0d13cb7ff61 (diff)
Small performance tweaks to mirror status JSON encoding
Do a few things to speed up the encoding of the JSON, including better usage of list comprehensions, less dynamic setattr() usage, and removal of the queryset specialization since we can easily do it outside of the encoder. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'mirrors/views.py')
-rw-r--r--mirrors/views.py7
1 files changed, 2 insertions, 5 deletions
diff --git a/mirrors/views.py b/mirrors/views.py
index 55c40c4d..0bf0a267 100644
--- a/mirrors/views.py
+++ b/mirrors/views.py
@@ -275,9 +275,6 @@ class MirrorStatusJSONEncoder(DjangoJSONEncoder):
if isinstance(obj, timedelta):
# always returned as integer seconds
return obj.days * 24 * 3600 + obj.seconds
- if hasattr(obj, '__iter__'):
- # mainly for queryset serialization
- return list(obj)
if isinstance(obj, MirrorUrl):
data = {attr: getattr(obj, attr) for attr in self.url_attributes}
country = obj.country
@@ -298,8 +295,8 @@ class ExtendedMirrorStatusJSONEncoder(MirrorStatusJSONEncoder):
if isinstance(obj, MirrorUrl):
data = super(ExtendedMirrorStatusJSONEncoder, self).default(obj)
cutoff = now() - DEFAULT_CUTOFF
- data['logs'] = obj.logs.filter(
- check_time__gte=cutoff).order_by('check_time')
+ data['logs'] = list(obj.logs.filter(
+ check_time__gte=cutoff).order_by('check_time'))
return data
if isinstance(obj, MirrorLog):
return {attr: getattr(obj, attr) for attr in self.log_attributes}