[stable-2.8] apt_facts - Fix cache related performance regression (#60511)

* apt_facts - Fix cache related performance regression

* Another minor performance improvement
(cherry picked from commit 0f35e4b7b9)

Co-authored-by: Sam Doran <sdoran@redhat.com>
This commit is contained in:
Sam Doran 2019-08-14 03:43:52 -04:00 committed by Toshio Kuratomi
parent 05d084b366
commit 59280a933e
2 changed files with 6 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- apt_facts - fix performance regression when getting facts about apt packages (https://github.com/ansible/ansible/issues/60450)

View file

@ -181,14 +181,16 @@ class APT(LibMgr):
@property
def pkg_cache(self):
if self._cache:
if self._cache is not None:
return self._cache
self._cache = self._lib.Cache()
return self._cache
def list_installed(self):
return [pk for pk in self.pkg_cache.keys() if self.pkg_cache[pk].is_installed]
# Store the cache to avoid running pkg_cache() for each item in the comprehension, which is very slow
cache = self.pkg_cache
return [pk for pk in cache.keys() if cache[pk].is_installed]
def get_package_details(self, package):
ac_pkg = self.pkg_cache[package].installed