2010-02-09 22:29:27 -08:00
|
|
|
from main.models import Arch, Repo, Package
|
2010-06-20 22:51:39 -07:00
|
|
|
from main.utils import cache_function
|
2010-02-04 18:44:46 -08:00
|
|
|
|
2010-06-20 22:51:39 -07:00
|
|
|
@cache_function(300)
|
2010-02-04 18:44:46 -08:00
|
|
|
def get_recent_updates():
|
|
|
|
# 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 = []
|
|
|
|
for a 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=a).order_by('-last_update')[:50])
|
2010-04-17 09:10:26 -07:00
|
|
|
pkgs.sort(key=lambda q: q.last_update)
|
|
|
|
updates = []
|
|
|
|
ctr = 0
|
|
|
|
while ctr < 15 and len(pkgs) > 0:
|
|
|
|
# not particularly happy with this logic, but it works.
|
|
|
|
p = pkgs.pop()
|
2010-02-26 17:37:15 -08:00
|
|
|
samepkgs = filter(lambda q: p.is_same_version(q) and p.repo == q.repo, pkgs)
|
2010-04-17 09:10:26 -07:00
|
|
|
samepkgs.append(p)
|
|
|
|
samepkgs.sort(key=lambda q: q.arch.name)
|
|
|
|
updates.append(samepkgs)
|
2010-02-04 18:44:46 -08:00
|
|
|
for q in samepkgs:
|
|
|
|
if p != q: pkgs.remove(q)
|
2010-04-17 09:10:26 -07:00
|
|
|
ctr += 1
|
|
|
|
return updates
|
2010-02-04 18:44:46 -08:00
|
|
|
|
|
|
|
# vim: set ts=4 sw=4 et:
|