summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-09-17 11:04:15 +0200
committerJürg Billeter <j@bitron.ch>2020-10-15 17:32:02 +0200
commit690080e6b4313de6447a9babff81563034f12348 (patch)
treec7ecd5591e996affb174c17943e3e6cd605d4172
parentb11d6ecaea197d4fd8777d9ace81a5ec5c52cb47 (diff)
downloadbuildstream-690080e6b4313de6447a9babff81563034f12348.tar.gz
_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()`.
-rw-r--r--src/buildstream/_elementsources.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/buildstream/_elementsources.py b/src/buildstream/_elementsources.py
index eed847e75..52f2bb8f3 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