* apt_facts - Fix cache related performance regression
* Another minor performance improvement
(cherry picked from commit 0f35e4b7b9)
Co-authored-by: Sam Doran <sdoran@redhat.com>
... | ... |
@@ -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 |