From a0ca4b5694f43c63ea13ba6908eff2bd53ee7ebb Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Sun, 19 Aug 2018 20:21:57 -0300 Subject: Fixed #29689 -- Improved performance of FileSystemStorage.listdir() and FilePathField with os.scandir(). --- django/core/files/storage.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'django/core') diff --git a/django/core/files/storage.py b/django/core/files/storage.py index b0168186ef..9929e20981 100644 --- a/django/core/files/storage.py +++ b/django/core/files/storage.py @@ -309,11 +309,11 @@ class FileSystemStorage(Storage): def listdir(self, path): path = self.path(path) directories, files = [], [] - for entry in os.listdir(path): - if os.path.isdir(os.path.join(path, entry)): - directories.append(entry) + for entry in os.scandir(path): + if entry.is_dir(): + directories.append(entry.name) else: - files.append(entry) + files.append(entry.name) return directories, files def path(self, name): -- cgit v1.3