From 9d3d647f0031edd31fc7442f9d2cd9729718e41c Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 8 Aug 2011 23:32:19 -0500 Subject: pactest: improve speed of local DB dependent rules We were doing some really silly stuff before and abusing the os.walk() call, having to walk the entire local database for every single PKG rule. We really only need top level directories, and we can cache any generated package since calls to db_read() are well-defined and only happen in one place. This speeds up the running of tests that may want to add 100 PKG_VERSION rules at once, where before we had to limit how many we used in order to not put a serious cramp in the speed of the test suite run. Signed-off-by: Dan McGee --- test/pacman/pmdb.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'test/pacman') diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index 63a156ec..5195ec64 100644 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -58,6 +58,8 @@ class pmdb(object): self.dbdir = os.path.join(root, util.PM_DBPATH, treename) self.dbfile = None self.is_local = True + self.read_dircache = None + self.read_pkgcache = {} else: self.dbdir = None self.dbfile = os.path.join(root, util.PM_SYNCDBPATH, treename + ".db") @@ -81,20 +83,24 @@ class pmdb(object): if not self.dbdir or not os.path.isdir(self.dbdir): return None - dbentry = "" - for roots, dirs, files in os.walk(self.dbdir): - for i in dirs: - [pkgname, pkgver, pkgrel] = i.rsplit("-", 2) - if pkgname == name: - dbentry = i - break - if not dbentry: + dbentry = None + if self.read_dircache is None: + self.read_dircache = os.listdir(self.dbdir) + for entry in self.read_dircache: + [pkgname, pkgver, pkgrel] = entry.rsplit("-", 2) + if pkgname == name: + dbentry = entry + break + if dbentry is None: return None - path = os.path.join(self.dbdir, dbentry) - [pkgname, pkgver, pkgrel] = dbentry.rsplit("-", 2) + if pkgname in self.read_pkgcache: + return self.read_pkgcache[pkgname] + pkg = pmpkg.pmpkg(pkgname, pkgver + "-" + pkgrel) + self.read_pkgcache[pkgname] = pkg + path = os.path.join(self.dbdir, dbentry) # desc filename = os.path.join(path, "desc") if not os.path.isfile(filename): -- cgit v1.2.3-70-g09d2