From 833798f4fb7f629fdb8d7e57b5f25b31d395fa5e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 11 Nov 2013 16:28:34 -0600 Subject: Filtered requiredby list for non-primary depends For something like gambas3 which has a makedepend on postgresql, we end up getting every single split package listed in the required by list for postgresql. This is a bit crazy and unnecessary, so slim it down a bit when possible by using a slightly crazy groupby function and some smarts in our get_requiredby function. Signed-off-by: Dan McGee --- main/models.py | 21 ++++++++++++++++++--- main/utils.py | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/main/models.py b/main/models.py index 2ace0109..b3c3e409 100644 --- a/main/models.py +++ b/main/models.py @@ -9,7 +9,7 @@ from django.contrib.auth.models import User from django.contrib.sites.models import Site from .fields import PositiveBigIntegerField -from .utils import set_created_field +from .utils import set_created_field, DependStandin from devel.models import DeveloperKey from packages.alpm import AlpmAPI @@ -247,6 +247,20 @@ class Package(models.Model): if len(requiredby) == 0: return requiredby + # do we have duplicate pkgbase values for non-primary depends? + # if so, filter it down to base packages only + def grouper(depend): + p = depend.pkg + return (depend.deptype, p.pkgbase, p.repo.testing, p.repo.staging) + + filtered = [] + for (typ, pkgbase, _, _), dep_pkgs in groupby(requiredby, grouper): + dep_pkgs = list(dep_pkgs) + if typ == 'D' or len(dep_pkgs) == 1: + filtered.extend(dep_pkgs) + else: + filtered.append(DependStandin(dep_pkgs)) + # find another package by this name in a different testing or staging # repo; if we can't, we can short-circuit some checks repo_q = (Q(repo__testing=(not self.repo.testing)) | @@ -255,13 +269,13 @@ class Package(models.Model): repo_q, pkgname=self.pkgname, arch=self.arch ).exclude(id=self.id).exists(): # there isn't one? short circuit, all required by entries are fine - return requiredby + return filtered trimmed = [] # for each unique package name, try to screen our package list down to # those packages in the same testing and staging category (yes or no) # iff there is a package in the same testing and staging category. - for _, dep_pkgs in groupby(requiredby, lambda x: x.pkg.pkgname): + for _, dep_pkgs in groupby(filtered, lambda x: x.pkg.pkgname): dep_pkgs = list(dep_pkgs) dep = dep_pkgs[0] if len(dep_pkgs) > 1: @@ -271,6 +285,7 @@ class Package(models.Model): if len(dep_pkgs) > 0: dep = dep_pkgs[0] trimmed.append(dep) + return trimmed def get_depends(self): diff --git a/main/utils.py b/main/utils.py index 9ee8db58..97cc540a 100644 --- a/main/utils.py +++ b/main/utils.py @@ -187,4 +187,18 @@ class PackageStandin(object): return '/packages/%s/%s/%s/' % ( self.repo.name.lower(), self.arch.name, self.pkgbase) + +class DependStandin(object): + '''Resembles a Depend object, and has a few of the same fields, but is + really a link to a base package rather than a single package.''' + def __init__(self, depends): + self._depends = depends + first = depends[0] + self.name = first.name + self.version = first.version + self.comparison = first.comparison + self.description = first.description + self.deptype = first.deptype + self.pkg = first.pkg.base_package() or PackageStandin(first.pkg) + # vim: set ts=4 sw=4 et: -- cgit v1.2.3-2-g168b