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

James Antill james at fedoraproject.org
Thu Feb 17 14:21:35 UTC 2011


On Thu, 2011-02-17 at 12:15 +0200, Panu Matilainen wrote:
> 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)

 Given that we got here, isn't this just the same as raising directly?
 If so it's probably easier to understand to just raise directly.

 Apart from that, ACK.



More information about the Yum-devel mailing list