Merge perf -> dev

--HG--
branch : dev
This commit is contained in:
Suha Can 2010-12-03 18:51:44 -08:00
commit a215e568e4
4 changed files with 34 additions and 14 deletions

View File

@ -5,12 +5,14 @@ using System.Linq;
using Autofac;
using Moq;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.Tests.Stubs;
namespace Orchard.Tests.DisplayManagement.Descriptors {
[TestFixture]
@ -21,12 +23,14 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
private TestVirtualPathProvider _testVirtualPathProvider;
protected override void Register(Autofac.ContainerBuilder builder) {
_descriptor = new ShellDescriptor { };
protected override void Register(ContainerBuilder builder) {
_descriptor = new ShellDescriptor();
_testViewEngine = new TestViewEngine();
_testVirtualPathProvider = new TestVirtualPathProvider();
builder.Register(ctx => _descriptor);
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubVirtualPathMonitor>().As<IVirtualPathMonitor>();
builder.RegisterType<ShapeTemplateBindingStrategy>().As<IShapeTableProvider>();
builder.RegisterType<BasicShapeTemplateHarvester>().As<IShapeTemplateHarvester>();
builder.RegisterInstance(_testViewEngine).As<IShapeTemplateViewEngine>();

View File

@ -1,9 +1,5 @@
using System;
using System.IO;
using System.Xml.Serialization;
using NHibernate;
using NHibernate;
using NHibernate.Cfg;
using Orchard.Data;
using Orchard.Data.Providers;
using Orchard.Environment;
using Orchard.Environment.Configuration;

View File

@ -1,10 +1,12 @@
using System.Collections.Concurrent;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using Orchard.Caching;
using Orchard.DisplayManagement.Implementation;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.Extensions;
@ -15,6 +17,8 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
public class ShapeTemplateBindingStrategy : IShapeTableProvider {
private readonly ShellDescriptor _shellDescriptor;
private readonly IExtensionManager _extensionManager;
private readonly ICacheManager _cacheManager;
private readonly IVirtualPathMonitor _virtualPathMonitor;
private readonly IVirtualPathProvider _virtualPathProvider;
private readonly IEnumerable<IShapeTemplateHarvester> _harvesters;
private readonly IEnumerable<IShapeTemplateViewEngine> _shapeTemplateViewEngines;
@ -24,11 +28,15 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
IEnumerable<IShapeTemplateHarvester> harvesters,
ShellDescriptor shellDescriptor,
IExtensionManager extensionManager,
ICacheManager cacheManager,
IVirtualPathMonitor virtualPathMonitor,
IVirtualPathProvider virtualPathProvider,
IEnumerable<IShapeTemplateViewEngine> shapeTemplateViewEngines) {
_harvesters = harvesters;
_shellDescriptor = shellDescriptor;
_extensionManager = extensionManager;
_cacheManager = cacheManager;
_virtualPathMonitor = virtualPathMonitor;
_virtualPathProvider = virtualPathProvider;
_shapeTemplateViewEngines = shapeTemplateViewEngines;
}
@ -49,13 +57,21 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath => {
var basePath = Path.Combine(extensionDescriptor.Location, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/');
var virtualPath = Path.Combine(basePath, subPath).Replace(Path.DirectorySeparatorChar, '/');
var fileNames = _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName);
var fileNames = _cacheManager.Get(virtualPath, ctx => {
ctx.Monitor(_virtualPathMonitor.WhenPathChanges(virtualPath));
return _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName);
});
return new { harvesterInfo.harvester, basePath, subPath, virtualPath, fileNames };
}));
var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve => {
var fileNames = ve.DetectTemplateFileNames(pathContext.fileNames);
return fileNames.Select(fileName => new { fileName = Path.GetFileNameWithoutExtension(fileName), fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace(Path.DirectorySeparatorChar, '/'), pathContext });
return fileNames.Select(
fileName => new {
fileName = Path.GetFileNameWithoutExtension(fileName),
fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace(Path.DirectorySeparatorChar, '/'),
pathContext
});
}));
var shapeContexts = fileContexts.SelectMany(fileContext => {

View File

@ -11,16 +11,21 @@ namespace Orchard.FileSystems.VirtualPath {
private readonly string _prefix = Guid.NewGuid().ToString("n");
private readonly IDictionary<string, Weak<Token>> _tokens = new Dictionary<string, Weak<Token>>();
private readonly IClock _clock;
private readonly IVirtualPathProvider _virtualPathProvider;
public DefaultVirtualPathMonitor(IClock clock) {
public DefaultVirtualPathMonitor(IClock clock, IVirtualPathProvider virtualPathProvider) {
_clock = clock;
_virtualPathProvider = virtualPathProvider;
_thunk = new Thunk(this);
}
public IVolatileToken WhenPathChanges(string virtualPath) {
// Fix this to monitor first existing parent directory.
var token = BindToken(virtualPath);
BindSignal(virtualPath);
IVolatileToken token = new Token(virtualPath);
if (_virtualPathProvider.DirectoryExists(virtualPath)) {
token = BindToken(virtualPath);
BindSignal(virtualPath);
}
return token;
}
@ -108,6 +113,5 @@ namespace Orchard.FileSystems.VirtualPath {
provider.Signal(key, value, reason);
}
}
}
}