summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-15 18:13:57 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-17 09:04:08 +0000
commitf44f97cbc012f8b5e219a11b06701c6544c308e6 (patch)
tree32ee1ec7bbda43010ae255d6c9bc8bc47b61bc85 /src
parentf3bdb4de710eccd021aaa5424860c88d03473aef (diff)
downloadbuildstream-f44f97cbc012f8b5e219a11b06701c6544c308e6.tar.gz
source: Cache mirror_directory instead of computing it everytime
This variable is accessed multiple times per run and can be slow on slow file systems.
Diffstat (limited to 'src')
-rw-r--r--src/buildstream/source.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/buildstream/source.py b/src/buildstream/source.py
index 59b6d3644..03c1301c5 100644
--- a/src/buildstream/source.py
+++ b/src/buildstream/source.py
@@ -330,6 +330,9 @@ class Source(Plugin):
self.__config = self.__extract_config(meta)
self.__first_pass = meta.first_pass
+ # cached values for commonly access values on the source
+ self.__mirror_directory = None
+
self._configure(self.__config)
COMMON_CONFIG_KEYS = ['kind', 'directory']
@@ -531,12 +534,14 @@ class Source(Plugin):
Returns:
(str): The directory belonging to this source
"""
+ if self.__mirror_directory is None:
+ # Create the directory if it doesnt exist
+ context = self._get_context()
+ directory = os.path.join(context.sourcedir, self.get_kind())
+ os.makedirs(directory, exist_ok=True)
+ self.__mirror_directory = directory
- # Create the directory if it doesnt exist
- context = self._get_context()
- directory = os.path.join(context.sourcedir, self.get_kind())
- os.makedirs(directory, exist_ok=True)
- return directory
+ return self.__mirror_directory
def translate_url(self, url, *, alias_override=None, primary=True):
"""Translates the given url which may be specified with an alias