Scheduler: cache Package instance more
authorZac Medico <zmedico@gentoo.org>
Thu, 6 Jan 2011 01:41:28 +0000 (17:41 -0800)
committerZac Medico <zmedico@gentoo.org>
Thu, 6 Jan 2011 01:41:28 +0000 (17:41 -0800)
This helps to avoid some cases in which emerge crashes due to ebuild
modification that leads to failure in aux_get/manifest check while
the Scheduler is running. Typically such modifications are harmless,
so it's beneficial to cache the metadata so that aux_get is less
likely to be called when it will fail.

pym/_emerge/Scheduler.py

index e30646fa98ced2b83945619d7bbf7ebb5d0a275d..d30abc40570c9b412e56e81d1cc04c8ecda83bf8 100644 (file)
@@ -433,12 +433,14 @@ class Scheduler(PollScheduler):
 
                if graph_config is None:
                        self._graph_config = None
+                       self._pkg_cache = {}
                        self._digraph = None
                        self._mergelist = []
                        self._deep_system_deps.clear()
                        return
 
                self._graph_config = graph_config
+               self._pkg_cache = graph_config.pkg_cache
                self._digraph = graph_config.graph
                self._mergelist = graph_config.mergelist
 
@@ -2003,18 +2005,19 @@ class Scheduler(PollScheduler):
                if installed:
                        operation = "nomerge"
 
-               if self._graph_config is not None:
-                       # Reuse existing instance when available.
-                       pkg = self._graph_config.pkg_cache.get(
-                               (type_name, root_config.root, cpv, operation, repo_key))
-                       if pkg is not None:
-                               return pkg
+               # Reuse existing instance when available.
+               pkg = self._pkg_cache.get(
+                       (type_name, root_config.root, cpv, operation, repo_key))
+               if pkg is not None:
+                       return pkg
 
                tree_type = depgraph.pkg_tree_map[type_name]
                db = root_config.trees[tree_type].dbapi
                db_keys = list(self.trees[root_config.root][
                        tree_type].dbapi._aux_cache_keys)
                metadata = zip(db_keys, db.aux_get(cpv, db_keys, myrepo=myrepo))
-               return Package(built=(type_name != 'ebuild'),
-                       cpv=cpv, metadata=metadata,
-                       root_config=root_config, installed=installed)
+               pkg = Package(built=(type_name != "ebuild"),
+                       cpv=cpv, installed=installed, metadata=metadata,
+                       root_config=root_config, type_name=type_name)
+               self._pkg_cache[pkg] = pkg
+               return pkg