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

Speedup audb.available() for S3/Minio #458

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Changes from 1 commit
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
45 changes: 27 additions & 18 deletions audb/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ def available(

""" # noqa: E501
databases = []

def add_database(name: str, version: str, repository: Repository):
"""Add database to list of databases."""
databases.append(
[
name,
repository.backend,
repository.host,
repository.name,
version,
]
)

for repository in config.REPOSITORIES:
try:
backend_interface = repository.create_backend_interface()
Expand All @@ -58,32 +71,28 @@ def available(
name = p.name
try:
for version in [str(x).split("/")[-1] for x in p / "db"]:
databases.append(
[
name,
repository.backend,
repository.host,
repository.name,
version,
]
)
add_database(name, version, repository)
except FileNotFoundError:
# If the `db` folder does not exist,
# we do not include the dataset
pass

elif repository.backend in ["minio", "s3"]:
# We can be much faster
# by avoiding using ls(),
# which would recursively lists all files
for obj in backend.list_objects(repository.name):
name = obj.object_name
header_file = f"/{name}/{define.HEADER_FILE}"
for _, version in backend_interface.ls(header_file):
hagenw marked this conversation as resolved.
Show resolved Hide resolved
add_database(name, version, repository)

else:
for path, version in backend_interface.ls("/"):
if path.endswith(define.HEADER_FILE):
name = path.split("/")[1]
databases.append(
[
name,
repository.backend,
repository.host,
repository.name,
version,
]
)
add_database(name, version, repository)

except audbackend.BackendError:
continue

Expand Down
Loading