Speed up LibraryPackageMap.update() by pulling NEEDED from the
authorZac Medico <zmedico@gentoo.org>
Fri, 16 Nov 2007 08:43:10 +0000 (08:43 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 16 Nov 2007 08:43:10 +0000 (08:43 -0000)
vardbapi.aux_get() cache. This greatly reduces the amount of
needless IO that has been happening just prior to the postinst
phase in dblink.treewalk(). We may want to consider having
LibraryPackageMap work directly from the vardbapi instead of
creating the intermediate /var/cache/edb/library_consumers file.

svn path=/main/trunk/; revision=8516

pym/portage/dbapi/vartree.py

index a35fcee4e1fad31288f43c74469a3a490b0243bf..aa8c75a504182e4ca210eebb4c2479414ee35c86 100644 (file)
@@ -146,8 +146,9 @@ class LibraryPackageMap(object):
        def update(self):
                """ Update the global library->consumer map for the given vdb instance. """
                obj_dict = {}
+               aux_get = self._dbapi.aux_get
                for cpv in self._dbapi.cpv_all():
-                       needed_list = grabfile(self._dbapi.getpath(cpv, "NEEDED"))
+                       needed_list = aux_get(cpv, ["NEEDED"])[0].splitlines()
                        for l in needed_list:
                                mysplit = l.split()
                                if len(mysplit) < 2:
@@ -517,6 +518,12 @@ class vardbapi(dbapi):
                        cache_valid = cache_mtime == mydir_mtime
                if cache_valid:
                        cache_incomplete = self._aux_cache_keys.difference(metadata)
+                       needed = metadata.get("NEEDED")
+                       if needed is None or "\n" not in needed:
+                               # Cached value has whitespace filtered, so it has to be pulled
+                               # again. This is temporary migration code which can be removed
+                               # later, since it only affects users who are running trunk.
+                               cache_incomplete.add("NEEDED")
                        if cache_incomplete:
                                # Allow self._aux_cache_keys to change without a cache version
                                # bump and efficiently recycle partial cache whenever possible.
@@ -558,7 +565,8 @@ class vardbapi(dbapi):
                                        myd = myf.read()
                                finally:
                                        myf.close()
-                               myd = " ".join(myd.split())
+                               if x != "NEEDED":
+                                       myd = " ".join(myd.split())
                        except IOError:
                                myd = ""
                        if x == "EAPI" and not myd: