From 20b64e42672d185821cc584dfa4b133ee259a144 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 28 Dec 2012 14:41:18 -0600 Subject: Reduce query count when retrieving satisfiers and providers Django doesn't attach the parent object to the child objects, even when queried through the related manager. This causes up to 3 extra queries: one to retrieve the package again, and one each for arch and repo retrieval. For a package like archboot, this drops the number of necessary queries for the package page from 805 to 222 (yes, this is still too high) and cuts the time spent waiting on the database from 505ms to 262ms. Signed-off-by: Dan McGee --- main/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'main') diff --git a/main/models.py b/main/models.py index b3cc97e..ba24645 100644 --- a/main/models.py +++ b/main/models.py @@ -271,10 +271,10 @@ class Package(models.Model): arches = None # TODO: we can use list comprehension and an 'in' query to make this more effective for dep in self.depends.all(): - pkg = dep.get_best_satisfier() + pkg = dep.get_best_satisfier(self) providers = None if not pkg: - providers = dep.get_providers() + providers = dep.get_providers(self) deps.append({'dep': dep, 'pkg': pkg, 'providers': providers}) # sort the list; deptype sorting makes this tricker than expected sort_order = {'D': 0, 'O': 1, 'M': 2, 'C': 3} -- cgit v1.2.3-24-g4f1b