From 8e7550cda9ed7ab1c067e0d887d1480b22af8d9c Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Sun, 1 May 2011 12:44:42 -0700 Subject: [PATCH] PERF: Use app relative virtual path for file monitoring This is so that the IVirtualPathMonitor implementation can properly cache virtual paths in a single entry. This decreases the number of entries by one or two order of magnitude when complex solutions are loaded (i.e. modules with lot of references to other modules). --HG-- branch : 1.x extra : transplant_source : %11%21n%FA%5Dy%E9%83%E3%86%86%D0%8Ba%FF%98%5C%8D/%22 --- .../Loaders/DynamicExtensionLoader.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs b/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs index 5e04c0cb9..f63ac0331 100644 --- a/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs +++ b/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs @@ -76,8 +76,9 @@ namespace Orchard.Environment.Extensions.Loaders { foreach (var path in GetDependencies(projectPath)) { Logger.Information("Monitoring virtual path \"{0}\"", path); - monitor(_virtualPathMonitor.WhenPathChanges(path)); - _reloadWorkaround.Monitor(_virtualPathMonitor.WhenPathChanges(path)); + var token = _virtualPathMonitor.WhenPathChanges(path); + monitor(token); + _reloadWorkaround.Monitor(token); } } } @@ -182,7 +183,7 @@ namespace Orchard.Environment.Extensions.Loaders { } protected IEnumerable GetDependencies(string projectPath) { - HashSet dependencies = new HashSet { projectPath }; + var dependencies = new HashSet { projectPath }; AddDependencies(projectPath, dependencies); @@ -205,6 +206,18 @@ namespace Orchard.Environment.Extensions.Loaders { ? _virtualPathProvider.GetProjectReferenceVirtualPath(projectPath, referenceDescriptor.SimpleName, referenceDescriptor.Path) : _virtualPathProvider.Combine(basePath, referenceDescriptor.Path); + // Normalize the virtual path (avoid ".." in the path name) + if (!string.IsNullOrEmpty(path)) { + try { + path = _virtualPathProvider.ToAppRelative(path); + } + catch (Exception e) { + // The initial path might have been invalid (e.g. path indicates a path outside the application root) + Logger.Information(e, "Path '{0}' cannot be made app relative", path); + path = null; + } + } + // Attempt to reference the project / library file if (!string.IsNullOrEmpty(path) && !currentSet.Contains(path) && _virtualPathProvider.TryFileExists(path)) { currentSet.Add(path);