From 2c8cce0e6f78434213482ae9bb77e4bb8250181b Mon Sep 17 00:00:00 2001 From: Joran Angevaare Date: Sun, 27 Dec 2020 22:49:06 +0100 Subject: [PATCH] Fix file search --- strax/storage/files.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/strax/storage/files.py b/strax/storage/files.py index 960746026..d15b03252 100644 --- a/strax/storage/files.py +++ b/strax/storage/files.py @@ -12,7 +12,6 @@ export, __all__ = strax.exporter() - RUN_METADATA_PATTERN = '%s-metadata.json' @@ -116,11 +115,16 @@ def _find(self, key, write, if exists and self._folder_matches(dirname, key, None, None): return bk - # Check metadata of all potentially matching data dirs for match... - for fn in self._subfolders(): - if self._folder_matches(fn, key, - fuzzy_for, fuzzy_for_options): - return self.backend_key(fn) + # Check metadata of all potentially matching data dirs for + # matches. This only makes sense for fuzzy searches since + # otherwise we should have had an exact match already. (Also + # really slows down st.select runs otherwise because we doing an + # entire search over all the files in self._subfolders for all + # non-available keys). + if fuzzy_for or fuzzy_for_options: + for fn in self._subfolders(): + if self._folder_matches(fn, key, fuzzy_for, fuzzy_for_options): + return self.backend_key(fn) raise strax.DataNotAvailable @@ -205,11 +209,11 @@ def get_metadata(self, dirname): prefix = dirname_to_prefix(dirname) metadata_json = f'{prefix}-metadata.json' md_path = osp.join(dirname, metadata_json) - + if not osp.exists(md_path): # Try to see if we are so fast that there exists a temp folder # with the metadata we need. - md_path = osp.join(dirname+'_temp', metadata_json) + md_path = osp.join(dirname + '_temp', metadata_json) if not osp.exists(md_path): # Try old-format metadata