[Yum-devel] [PATCH] Avoid unwanted header loads from RPMInstalledPackage() __getattr__

Panu Matilainen pmatilai at laiskiainen.org
Thu Feb 17 10:15:30 UTC 2011


At least hasattr() calls for _cache_prco_names_* and _prco_lookup
were causing headers to be loaded when not wanted at all, causing
headers for all to-be updated packages to be kept in memory throughout
the entire transaction.

It'd probably make sense to only ever load the header if the requested
attribute is a valid rpm tag, but leaving that for another patch...
---
 yum/rpmsack.py |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index 227ed89..e0798ce 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -67,13 +67,18 @@ class RPMInstalledPackage(YumInstalledPackage):
             raise Errors.PackageSackError, 'Rpmdb changed underneath us'
 
     def __getattr__(self, varname):
-        self.hdr = val = self._get_hdr()
-        self._has_hdr = True
         # If these existed, then we wouldn't get here ... and nothing in the DB
         # starts and ends with __'s. So these are missing.
         if varname.startswith('__') and varname.endswith('__'):
             raise AttributeError, "%s has no attribute %s" % (self, varname)
-            
+
+        # At least _cache_prco_names and _prco_lookup need the real attribute
+        if varname.startswith('_'):
+            return object.__getattr__(self, varname)
+
+        # Only grab header if it might actually be needed (see above)
+        self.hdr = val = self._get_hdr()
+        self._has_hdr = True
         if varname != 'hdr':   #  This is unusual, for anything that happens
             val = val[varname] # a lot we should preload at __init__.
                                # Also note that pkg.no_value raises KeyError.
-- 
1.7.4



More information about the Yum-devel mailing list