From 1bcf62cb817ec321a38131dc2a0506609e537f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Thu, 17 Sep 2020 11:04:15 +0200 Subject: _elementsources.py: Make cache query explicit Cache query can be fairly expensive as it checks the presence of all blobs. Make this more explicit with a `query_cache()` method, instead of implicitly querying the cache on the first call to `cached()`. --- src/buildstream/_elementsources.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/buildstream/_elementsources.py b/src/buildstream/_elementsources.py index a15d20ecb..a3e510543 100644 --- a/src/buildstream/_elementsources.py +++ b/src/buildstream/_elementsources.py @@ -293,7 +293,7 @@ class ElementSources: length = min(len(key), context.log_key_length) return key[:length] - # cached(): + # query_cache(): # # Check if the element sources are cached in CAS, generating the source # cache keys if needed. @@ -301,10 +301,7 @@ class ElementSources: # Returns: # (bool): True if the element sources are cached # - def cached(self): - if self._cached is not None: - return self._cached - + def query_cache(self): cas = self._context.get_cascache() elementsourcescache = self._elementsourcescache @@ -321,6 +318,18 @@ class ElementSources: self._cached = True return True + # cached() + # + # Return whether the element sources are cached in CAS. This must be + # called only when all sources are resolved. + # + # Returns: + # (bool): True if the element sources are cached + # + def cached(self): + assert self._cached is not None + return self._cached + # is_resolved(): # # Get whether all sources of the element are resolved @@ -368,6 +377,8 @@ class ElementSources: unique_key = self.get_unique_key() self._cache_key = _cachekey.generate_key(unique_key) + self.query_cache() + # preflight(): # # A internal wrapper for calling the abstract preflight() method on -- cgit v1.2.1