Fixes: U4-5780 RenderActionInvoker needs a perf fix with caching when it's using reflection

This commit is contained in:
Shannon
2014-11-11 17:52:40 +11:00
parent 9112c05477
commit 4d9f6ccd22

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Web.Mvc;
using System.Web.Mvc.Async;
@@ -10,6 +12,8 @@ namespace Umbraco.Web.Mvc
public class RenderActionInvoker : AsyncControllerActionInvoker
{
private static readonly ConcurrentDictionary<Type, ReflectedActionDescriptor> IndexDescriptors = new ConcurrentDictionary<Type, ReflectedActionDescriptor>();
/// <summary>
/// Ensures that if an action for the Template name is not explicitly defined by a user, that the 'Index' action will execute
/// </summary>
@@ -27,12 +31,15 @@ namespace Umbraco.Web.Mvc
//check if the controller is an instance of IRenderMvcController
if (controllerContext.Controller is IRenderMvcController)
{
return new ReflectedActionDescriptor(
controllerContext.Controller.GetType().GetMethods()
.First(x => x.Name == "Index" &&
x.GetCustomAttributes(typeof (NonActionAttribute), false).Any() == false),
"Index",
controllerDescriptor);
return IndexDescriptors.GetOrAdd(controllerContext.Controller.GetType(),
type => new ReflectedActionDescriptor(
controllerContext.Controller.GetType().GetMethods()
.First(x => x.Name == "Index" &&
x.GetCustomAttributes(typeof (NonActionAttribute), false).Any() == false),
"Index",
controllerDescriptor));
}
}