mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
PERF: During startup, re-use the retrieve file modification dates
to compute the file hash to store into the ExtensionDependencies file. This allows skipping doing additional file I/O on dynamic modules when they are activated. --HG-- branch : 1.x
This commit is contained in:
@@ -74,7 +74,7 @@ namespace Orchard.Environment.Extensions {
|
||||
|
||||
// And finally save the new entries in the dependencies folder
|
||||
_dependenciesFolder.StoreDescriptors(context.NewDependencies);
|
||||
_extensionDependenciesManager.StoreDependencies(context.NewDependencies);
|
||||
_extensionDependenciesManager.StoreDependencies(context.NewDependencies, path => GetFileHash(context, path));
|
||||
|
||||
Logger.Information("Done loading extensions...");
|
||||
|
||||
@@ -85,6 +85,17 @@ namespace Orchard.Environment.Extensions {
|
||||
}
|
||||
}
|
||||
|
||||
private string GetFileHash(ExtensionLoadingContext context, string path) {
|
||||
var hash = new Hash();
|
||||
hash.AddString(path);
|
||||
|
||||
DateTime dateTime;
|
||||
if (context.VirtualPathModficationDates.TryGetValue(path, out dateTime)) {
|
||||
hash.AddDateTime(dateTime);
|
||||
}
|
||||
return hash.Value;
|
||||
}
|
||||
|
||||
private void ProcessExtension(ExtensionLoadingContext context, ExtensionDescriptor extension) {
|
||||
|
||||
var extensionProbes = context.AvailableExtensionsProbes.ContainsKey(extension.Id) ?
|
||||
|
||||
@@ -15,13 +15,11 @@ namespace Orchard.FileSystems.Dependencies {
|
||||
/// </summary>
|
||||
public class DefaultExtensionDependenciesManager : IExtensionDependenciesManager {
|
||||
private readonly IAppDataFolder _appDataFolder;
|
||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||
private const string BasePath = "Dependencies";
|
||||
private const string FileName = "Dependencies.ModuleCompilation.xml";
|
||||
|
||||
public DefaultExtensionDependenciesManager(IAppDataFolder appDataFolder, IVirtualPathProvider virtualPathProvider) {
|
||||
public DefaultExtensionDependenciesManager(IAppDataFolder appDataFolder) {
|
||||
_appDataFolder = appDataFolder;
|
||||
_virtualPathProvider = virtualPathProvider;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
@@ -31,10 +29,10 @@ namespace Orchard.FileSystems.Dependencies {
|
||||
get { return _appDataFolder.Combine(BasePath, FileName); }
|
||||
}
|
||||
|
||||
public void StoreDependencies(IEnumerable<DependencyDescriptor> dependencyDescriptors) {
|
||||
public void StoreDependencies(IEnumerable<DependencyDescriptor> dependencyDescriptors, Func<string, string> fileHashProvider) {
|
||||
Logger.Information("Storing module dependency file.");
|
||||
|
||||
var newDocument = CreateDocument(dependencyDescriptors);
|
||||
var newDocument = CreateDocument(dependencyDescriptors, fileHashProvider);
|
||||
var previousDocument = ReadDocument(PersistencePath);
|
||||
if (CompareXmlDocuments(newDocument, previousDocument)) {
|
||||
Logger.Debug("Existing document is identical to new one. Skipping save.");
|
||||
@@ -55,7 +53,7 @@ namespace Orchard.FileSystems.Dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
private XDocument CreateDocument(IEnumerable<DependencyDescriptor> dependencies) {
|
||||
private XDocument CreateDocument(IEnumerable<DependencyDescriptor> dependencies, Func<string, string> fileHashProvider) {
|
||||
Func<string, XName> ns = (name => XName.Get(name));
|
||||
|
||||
var document = new XDocument();
|
||||
@@ -65,13 +63,13 @@ namespace Orchard.FileSystems.Dependencies {
|
||||
new XElement(ns("ModuleName"), d.Name),
|
||||
new XElement(ns("LoaderName"), d.LoaderName),
|
||||
new XElement(ns("VirtualPath"), d.VirtualPath),
|
||||
new XElement(ns("FileHash"), _virtualPathProvider.GetFileHash(d.VirtualPath)),
|
||||
new XElement(ns("FileHash"), fileHashProvider(d.VirtualPath)),
|
||||
new XElement(ns("References"), FilterReferences(d.References)
|
||||
.Select(r => new XElement(ns("Reference"),
|
||||
new XElement(ns("Name"), r.Name),
|
||||
new XElement(ns("LoaderName"), r.LoaderName),
|
||||
new XElement(ns("VirtualPath"), r.VirtualPath),
|
||||
new XElement(ns("FileHash"), _virtualPathProvider.GetFileHash(r.VirtualPath)))).ToArray())));
|
||||
new XElement(ns("FileHash"), fileHashProvider(r.VirtualPath)))).ToArray())));
|
||||
|
||||
document.Root.Add(elements);
|
||||
return document;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Caching;
|
||||
|
||||
namespace Orchard.FileSystems.Dependencies {
|
||||
public interface IExtensionDependenciesManager : IVolatileProvider {
|
||||
void StoreDependencies(IEnumerable<DependencyDescriptor> dependencyDescriptors);
|
||||
void StoreDependencies(IEnumerable<DependencyDescriptor> dependencyDescriptors, Func<string, string> fileHashProvider);
|
||||
IEnumerable<string> GetVirtualPathDependencies(DependencyDescriptor descriptor);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Orchard.Utility {
|
||||
/// <summary>
|
||||
@@ -9,10 +10,10 @@ namespace Orchard.Utility {
|
||||
public class Hash {
|
||||
private long _hash;
|
||||
|
||||
public string Value { get { return _hash.ToString(); } }
|
||||
public string Value { get { return _hash.ToString("x", CultureInfo.InvariantCulture); } }
|
||||
|
||||
public void AddString(string value) {
|
||||
if ( string.IsNullOrEmpty(value) )
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return;
|
||||
_hash += value.GetHashCode();
|
||||
}
|
||||
@@ -21,5 +22,9 @@ namespace Orchard.Utility {
|
||||
AddString(type.AssemblyQualifiedName);
|
||||
AddString(type.FullName);
|
||||
}
|
||||
|
||||
public void AddDateTime(DateTime dateTime) {
|
||||
_hash += dateTime.ToUniversalTime().ToBinary();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user