summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-03-13 12:03:37 -0500
committerDan McGee <dan@archlinux.org>2011-03-13 12:03:37 -0500
commit9d17938782d661a313b766bb6a3713fbfb5bb155 (patch)
treed64f0c4ce9d5286aace03ca0e5e649c78dc7619a /public
parentba1ca7db1e16400651bb746b8b80f2b30cf88a2f (diff)
Move magic numbers into a function argument
Instead of having the '15 most recent' bit hardcoded, specify it as the default but allow value to be overridden by any caller. We don't make use of this yet, but it is not hard to do. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'public')
-rw-r--r--public/utils.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/public/utils.py b/public/utils.py
index 81f589f7..8ce2af45 100644
--- a/public/utils.py
+++ b/public/utils.py
@@ -4,19 +4,20 @@ from main.models import Arch, Package
from main.utils import cache_function
@cache_function(300)
-def get_recent_updates():
+def get_recent_updates(number=15):
# This is a bit of magic. We are going to show 15 on the front page, but we
# want to try and eliminate cross-architecture wasted space. Pull enough
# packages that we can later do some screening and trim out the fat.
pkgs = []
+ # grab a few extra so we can hopefully catch everything we need
+ fetch = number * 4
for arch in Arch.objects.all():
- # grab a few extra so we can hopefully catch everything we need
pkgs += list(Package.objects.select_related(
- 'arch', 'repo').filter(arch=arch).order_by('-last_update')[:50])
+ 'arch', 'repo').filter(arch=arch).order_by('-last_update')[:fetch])
pkgs.sort(key=attrgetter('last_update'))
updates = []
ctr = 0
- while ctr < 15 and len(pkgs) > 0:
+ while ctr < number and len(pkgs) > 0:
# not particularly happy with this logic, but it works.
p = pkgs.pop()
is_same = lambda q: p.is_same_version(q) and p.repo == q.repo