From d856e5e567f9285b5c8039d99154a3fb564c31fd Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 26 Jun 2011 14:34:03 +0100 Subject: [PATCH] Batch up queries to PackageKit PackageKit (on Debian at least) takes about 0.7s per request, regardless of how many packages you ask about. This patch reduces the time taken to get the necessary information about the Subversion feed from about 6.7s to 0.7s. --- zeroinstall/injector/packagekit.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/zeroinstall/injector/packagekit.py b/zeroinstall/injector/packagekit.py index 8363d3c..2214e09 100644 --- a/zeroinstall/injector/packagekit.py +++ b/zeroinstall/injector/packagekit.py @@ -29,6 +29,10 @@ class PackageKit(object): self._candidates = {} # { package_name : (version, arch, size) | Blocker } + # PackageKit is really slow at handling separate queries, so we use this to + # batch them up. + self._next_batch = set() + @property def available(self): return self.pk is not None @@ -85,6 +89,14 @@ class PackageKit(object): def fetch_candidates(self, package_names): assert self.pk + # Batch requests up + self._next_batch |= set(package_names) + yield + package_names = self._next_batch + self._next_batch = set() + # The first fetch_candidates instance will now have all the packages + # For the others, package_names will now be empty + known = [self._candidates[p] for p in package_names if p in self._candidates] # (use set because a single task may be checking multiple packages and we need # to avoid duplicates). -- 2.11.4.GIT