Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up st.select_runs by factor ~100 with strict "_find" in files-storage #371

Merged
merged 1 commit into from
Dec 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions strax/storage/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

export, __all__ = strax.exporter()


RUN_METADATA_PATTERN = '%s-metadata.json'


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down