mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
PERF: Adding various logging calls related to startup performance
--HG-- branch : 1.x extra : transplant_source : %DC%AB%0E%89%B4%01%20%17%29%87%0F%D86%3A%FE%EE%A2%FB%D9%94
This commit is contained in:
@@ -5,6 +5,7 @@ using Autofac.Features.Metadata;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Utility;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors {
|
||||
@@ -21,10 +22,15 @@ namespace Orchard.DisplayManagement.Descriptors {
|
||||
_extensionManager = extensionManager;
|
||||
_cacheManager = cacheManager;
|
||||
_bindingStrategies = bindingStrategies;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public ShapeTable GetShapeTable(string themeName) {
|
||||
return _cacheManager.Get(themeName ?? "", x => {
|
||||
Logger.Information("Start building shape table");
|
||||
|
||||
var builderFactory = new ShapeTableBuilderFactory();
|
||||
foreach (var bindingStrategy in _bindingStrategies) {
|
||||
Feature strategyDefaultFeature = bindingStrategy.Metadata.ContainsKey("Feature") ?
|
||||
@@ -47,10 +53,13 @@ namespace Orchard.DisplayManagement.Descriptors {
|
||||
return descriptor;
|
||||
})).ToList();
|
||||
|
||||
return new ShapeTable {
|
||||
var result = new ShapeTable {
|
||||
Descriptors = descriptors.ToDictionary(sd => sd.ShapeType, StringComparer.OrdinalIgnoreCase),
|
||||
Bindings = descriptors.SelectMany(sd => sd.Bindings).ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase),
|
||||
};
|
||||
|
||||
Logger.Information("Done building shape table");
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
||||
}
|
||||
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
Logger.Information("Start discovering shapes");
|
||||
|
||||
var harvesterInfos = _harvesters.Select(harvester => new { harvester, subPaths = harvester.SubPaths() });
|
||||
|
||||
var availableFeatures = _extensionManager.AvailableFeatures();
|
||||
@@ -58,6 +60,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
||||
var activeExtensions = Once(activeFeatures);
|
||||
|
||||
var hits = activeExtensions.SelectMany(extensionDescriptor => {
|
||||
Logger.Information("Start discovering candidate views filenames");
|
||||
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, '/');
|
||||
@@ -66,7 +69,8 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
||||
return _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName);
|
||||
});
|
||||
return new { harvesterInfo.harvester, basePath, subPath, virtualPath, fileNames };
|
||||
}));
|
||||
})).ToList();
|
||||
Logger.Information("Done discovering candidate views filenames");
|
||||
|
||||
var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve => {
|
||||
var fileNames = ve.DetectTemplateFileNames(pathContext.fileNames);
|
||||
@@ -109,6 +113,8 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
||||
shapeDescriptor => displayContext => Render(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit));
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Information("Done discovering shapes");
|
||||
}
|
||||
|
||||
private bool FeatureIsEnabled(FeatureDescriptor fd) {
|
||||
@@ -117,8 +123,13 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
||||
}
|
||||
|
||||
private IHtmlString Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) {
|
||||
Logger.Information("Rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
|
||||
|
||||
var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
|
||||
return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
|
||||
var result = htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
|
||||
|
||||
Logger.Information("Done rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Mvc.Spooling;
|
||||
using Orchard.Themes;
|
||||
using Orchard.UI.Admin;
|
||||
@@ -23,8 +24,11 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
||||
_workContext = workContext;
|
||||
_themeAwareViewEngine = themeAwareViewEngine;
|
||||
_displayHelperFactory = displayHelperFactory;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) {
|
||||
return _themeAwareViewEngine.FindPartialView(controllerContext, partialViewName, useCache, true);
|
||||
}
|
||||
@@ -41,6 +45,8 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
||||
}
|
||||
|
||||
var layoutView = new LayoutView((viewContext, writer, viewDataContainer) => {
|
||||
Logger.Information("Rendering layout view");
|
||||
|
||||
var childContentWriter = new HtmlStringWriter();
|
||||
|
||||
var childContentViewContext = new ViewContext(
|
||||
@@ -57,6 +63,7 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
||||
IHtmlString result = display(_workContext.Layout);
|
||||
writer.Write(result.ToHtmlString());
|
||||
|
||||
Logger.Information("Done rendering layout view");
|
||||
}, (context, view) => viewResult.ViewEngine.ReleaseView(context, viewResult.View));
|
||||
|
||||
return new ViewEngineResult(layoutView, this);
|
||||
|
||||
Reference in New Issue
Block a user