Skip to content

Commit

Permalink
fs_storage: fix _ls_check_connection when dealing with huge amount of…
Browse files Browse the repository at this point in the history
… files
  • Loading branch information
sebalix committed Mar 4, 2025
1 parent 87e522c commit 84a4755
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion fs_storage/models/fs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

_logger = logging.getLogger(__name__)

LS_NON_EXISTING_FILE = ".NON_EXISTING_FILE"


# TODO: useful for the whole OCA?
def deprecated(reason):
Expand Down Expand Up @@ -296,7 +298,14 @@ def _marker_file_check_connection(self, fs):
fs.touch(marker_file_name)

def _ls_check_connection(self, fs):
fs.ls("", detail=False)
# NOTE: run 'ls' on a non existing file to get better perf on FS
# having a huge amount of files in root folder.
# Getting a 'FileNotFoundError' means that the connection is working well.
try:
fs.ls(LS_NON_EXISTING_FILE, detail=False)

Check warning on line 305 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L304-L305

Added lines #L304 - L305 were not covered by tests
# pylint: disable=except-pass
except FileNotFoundError:
pass

Check warning on line 308 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L307-L308

Added lines #L307 - L308 were not covered by tests

def _check_connection(self, fs, check_connection_method):
if check_connection_method == "marker_file":
Expand Down

0 comments on commit 84a4755

Please sign in to comment.