From f41132b16a3e3e64b6fb9d2b7bc8af499def7331 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Sat, 19 Apr 2014 14:49:04 -0700 Subject: [PATCH] Improving route based constraints The IArchiveConstraint is a singleton as the routes are singletons too. However the path resolution is per tenant, and when accessing archive pages where lots of links are constructed simultaneously there are collisions and DataReader/Connections failures. The solution is to use the IAliasHolder which is also a singleton and doesn't make any query. --- .../Services/PathResolutionService.cs | 2 +- .../Orchard.Blogs/Orchard.Blogs.csproj | 4 +++ .../Routing/ArchiveConstraint.CS | 28 +++++++++++++------ .../Orchard.Blogs/Routing/RsdConstraint.CS | 26 +++++++++++------ 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/PathResolutionService.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/PathResolutionService.cs index e46be3167..763cc4ade 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/PathResolutionService.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/PathResolutionService.cs @@ -24,7 +24,7 @@ namespace Orchard.Autoroute.Services { return null; } - return _contentManager.Get(autorouteRecord.Id).As(); + return _contentManager.Get(autorouteRecord.ContentItemRecord.Id).As(); } } } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj index e4d5f059e..ab91981ae 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj @@ -153,6 +153,10 @@ {9916839C-39FC-4CEB-A5AF-89CA7E87119F} Orchard.Core + + {475b6c45-b27c-438b-8966-908b9d6d1077} + Orchard.Alias + {66fccd76-2761-47e3-8d11-b45d0001ddaa} Orchard.Autoroute diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS index f1617a781..0b2d42d4b 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS @@ -1,16 +1,16 @@ +using Orchard.Alias.Implementation.Holder; +using Orchard.Blogs.Models; using System; +using System.Collections.Generic; using System.Web; using System.Web.Routing; -using Orchard.Autoroute.Services; -using Orchard.Blogs.Models; -using Orchard.ContentManagement; namespace Orchard.Blogs.Routing { public class ArchiveConstraint : IArchiveConstraint { - private readonly IPathResolutionService _pathResolutionService; + private readonly IAliasHolder _aliasHolder; - public ArchiveConstraint(IPathResolutionService pathResolutionService) { - _pathResolutionService = pathResolutionService; + public ArchiveConstraint(IAliasHolder aliasHolder) { + _aliasHolder = aliasHolder; } public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { @@ -37,9 +37,21 @@ namespace Orchard.Blogs.Routing { return false; } - var autoroute = _pathResolutionService.GetPath(path); + IDictionary routeValues; + if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out routeValues)) { + return false; + } - return autoroute != null && autoroute.Is(); + var isBlog = + //routeValues.ContainsKey("area") && + //routeValues["area"] == "Orchard.Blogs" && + routeValues.ContainsKey("controller") && + routeValues["controller"] == "Blog" && + routeValues.ContainsKey("action") && + routeValues["action"] == "Item" + ; + + return isBlog; } return false; diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RsdConstraint.CS b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RsdConstraint.CS index d8ec635d2..2dc4e44c9 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RsdConstraint.CS +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RsdConstraint.CS @@ -1,16 +1,15 @@ +using Orchard.Alias.Implementation.Holder; using System; +using System.Collections.Generic; using System.Web; using System.Web.Routing; -using Orchard.Autoroute.Services; -using Orchard.Blogs.Models; -using Orchard.ContentManagement; namespace Orchard.Blogs.Routing { public class RsdConstraint : IRsdConstraint { - private readonly IPathResolutionService _pathResolutionService; + private readonly IAliasHolder _aliasHolder; - public RsdConstraint(IPathResolutionService pathResolutionService) { - _pathResolutionService = pathResolutionService; + public RsdConstraint(IAliasHolder aliasHolder) { + _aliasHolder = aliasHolder; } public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { @@ -26,9 +25,20 @@ namespace Orchard.Blogs.Routing { return false; } - var autoroute = _pathResolutionService.GetPath(path); + IDictionary routeValues; + if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out routeValues)) { + return false; + } + + var isBlog = + //routeValues.ContainsKey("area") && + //routeValues["area"] == "Orchard.Blogs" && + routeValues.ContainsKey("controller") && + routeValues["area"] == "Blog" && + routeValues.ContainsKey("action") && + routeValues["area"] == "Item" + ; - return autoroute != null && autoroute.Is(); } return false;