From 90ee532684f148eb15f3c11172a1cdf0ec5545b4 Mon Sep 17 00:00:00 2001 From: Abderrahim Kitouni Date: Thu, 31 Oct 2024 21:40:55 +0100 Subject: [PATCH] _stream: Only query cache for the requested elements query_cache() used to query the cache for the elements passed and all their (build and runtime) dependencies. This is wasteful since most of the time, we don't need all this cache query. As it turns out, this is only needed by `bst show` to be able to figure out the buildable status and the cache key in all circumsances. This commit makes this behaviour optional, and only enables it from `bst show`. --- src/buildstream/_frontend/cli.py | 2 +- src/buildstream/_stream.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index 89475b5a1..e827d18ae 100644 --- a/src/buildstream/_frontend/cli.py +++ b/src/buildstream/_frontend/cli.py @@ -649,7 +649,7 @@ def show(app, elements, deps, except_, order, format_): # Don't spend time interrogating the cache if we don't need to show element state if need_state: - app.stream.query_cache(dependencies) + app.stream.query_cache(dependencies, need_state=True) if order == "alpha": dependencies = sorted(dependencies) diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index 2266b27f0..61462ed2c 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -190,13 +190,16 @@ def load_selection( # sources_of_cached_elements (bool): True to query the source cache for elements with a cached artifact # only_sources (bool): True to only query the source cache # - def query_cache(self, elements, *, sources_of_cached_elements=False, only_sources=False): + def query_cache(self, elements, *, sources_of_cached_elements=False, only_sources=False, need_state=False): # It doesn't make sense to combine these flags assert not sources_of_cached_elements or not only_sources with self._context.messenger.simple_task("Query cache", silent_nested=True) as task: - # Enqueue complete build plan as this is required to determine `buildable` status. - plan = list(_pipeline.dependencies(elements, _Scope.ALL)) + if need_state: + # Enqueue complete build plan as this is required to determine `buildable` status. + plan = list(_pipeline.dependencies(elements, _Scope.ALL)) + else: + plan = elements if self._context.remote_cache_spec: # Parallelize cache queries if a remote cache is configured