Optimizing FileSystemStorageProvider.ListProfiles

This commit is contained in:
Lombiq
2019-02-20 18:12:00 +01:00
parent 5d74f4380c
commit 056233c9c5

View File

@@ -271,17 +271,18 @@ namespace Orchard.FileSystems.Media {
/// <param name="path">The relative path to the file to be deleted.</param> /// <param name="path">The relative path to the file to be deleted.</param>
/// <returns></returns> /// <returns></returns>
private IEnumerable<FileInfo> ListProfiles(string path) { private IEnumerable<FileInfo> ListProfiles(string path) {
var directoryInfo = new DirectoryInfo(MapStorage("_Profiles"));
if (!directoryInfo.Exists) return Enumerable.Empty<FileInfo>();
var filenameWithExtension = Path.GetFileName(path) ?? ""; var filenameWithExtension = Path.GetFileName(path) ?? "";
var urlpath = GetPublicUrl(path); var urlpath = GetPublicUrl(path);
var fileLocation = urlpath.Substring(0, urlpath.Length - filenameWithExtension.Length); var fileLocation = urlpath.Substring(0, urlpath.Length - filenameWithExtension.Length);
var hashpath = fileLocation.GetHashCode().ToString("x").ToLowerInvariant(); var hashpath = fileLocation.GetHashCode().ToString("x").ToLowerInvariant();
DirectoryInfo directoryInfo = new DirectoryInfo(MapStorage("_Profiles"));
return directoryInfo.Exists ? return directoryInfo
directoryInfo .GetFiles(filenameWithExtension, SearchOption.AllDirectories)
.GetFiles(filenameWithExtension, SearchOption.AllDirectories) .Where(x => x.Directory.Name.Equals(hashpath));
.Where(x => x.Directory.Name.Equals(hashpath)) :
Enumerable.Empty<FileInfo>();
} }
/// <summary> /// <summary>