From 056233c9c57bbdec38caced2e3a3a2dd238abfca Mon Sep 17 00:00:00 2001 From: Lombiq Date: Wed, 20 Feb 2019 18:12:00 +0100 Subject: [PATCH] Optimizing FileSystemStorageProvider.ListProfiles --- .../FileSystems/Media/FileSystemStorageProvider.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs b/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs index d105fd750..782590892 100644 --- a/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs +++ b/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs @@ -271,17 +271,18 @@ namespace Orchard.FileSystems.Media { /// The relative path to the file to be deleted. /// private IEnumerable ListProfiles(string path) { + var directoryInfo = new DirectoryInfo(MapStorage("_Profiles")); + + if (!directoryInfo.Exists) return Enumerable.Empty(); + var filenameWithExtension = Path.GetFileName(path) ?? ""; var urlpath = GetPublicUrl(path); var fileLocation = urlpath.Substring(0, urlpath.Length - filenameWithExtension.Length); var hashpath = fileLocation.GetHashCode().ToString("x").ToLowerInvariant(); - DirectoryInfo directoryInfo = new DirectoryInfo(MapStorage("_Profiles")); - return directoryInfo.Exists ? - directoryInfo - .GetFiles(filenameWithExtension, SearchOption.AllDirectories) - .Where(x => x.Directory.Name.Equals(hashpath)) : - Enumerable.Empty(); + return directoryInfo + .GetFiles(filenameWithExtension, SearchOption.AllDirectories) + .Where(x => x.Directory.Name.Equals(hashpath)); } ///