Browse code

[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>

Sam Doran authored on 2019/08/14 16:43:52
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+bugfixes:
1
+  - apt_facts - fix performance regression when getting facts about apt packages (https://github.com/ansible/ansible/issues/60450)
... ...
@@ -181,14 +181,16 @@ class APT(LibMgr):
181 181
 
182 182
     @property
183 183
     def pkg_cache(self):
184
-        if self._cache:
184
+        if self._cache is not None:
185 185
             return self._cache
186 186
 
187 187
         self._cache = self._lib.Cache()
188 188
         return self._cache
189 189
 
190 190
     def list_installed(self):
191
-        return [pk for pk in self.pkg_cache.keys() if self.pkg_cache[pk].is_installed]
191
+        # Store the cache to avoid running pkg_cache() for each item in the comprehension, which is very slow
192
+        cache = self.pkg_cache
193
+        return [pk for pk in cache.keys() if cache[pk].is_installed]
192 194
 
193 195
     def get_package_details(self, package):
194 196
         ac_pkg = self.pkg_cache[package].installed