Merge dev-v8 into temp-u4-8497
This commit is contained in:
@@ -1,22 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.XPath;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Xml;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web;
|
||||
using umbraco;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using umbraco.BusinessLogic;
|
||||
using Umbraco.Core.Cache;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
@@ -92,17 +86,27 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
// cache if we have a content and not previewing
|
||||
if (content != null && preview == false && _routesCache != null)
|
||||
{
|
||||
var domainRootNodeId = route.StartsWith("/") ? -1 : int.Parse(route.Substring(0, route.IndexOf('/')));
|
||||
var iscanon = DomainHelper.ExistsDomainInPath(_domainCache.GetAll(false), content.Path, domainRootNodeId) == false;
|
||||
// and only if this is the canonical url (the one GetUrl would return)
|
||||
if (iscanon)
|
||||
_routesCache.Store(content.Id, route);
|
||||
}
|
||||
AddToCacheIfDeepestRoute(content, route);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
private void AddToCacheIfDeepestRoute(IPublishedContent content, string route)
|
||||
{
|
||||
var domainRootNodeId = route.StartsWith("/") ? -1 : int.Parse(route.Substring(0, route.IndexOf('/')));
|
||||
|
||||
// so we have a route that maps to a content... say "1234/path/to/content" - however, there could be a
|
||||
// domain set on "to" and route "4567/content" would also map to the same content - and due to how
|
||||
// urls computing work (by walking the tree up to the first domain we find) it is that second route
|
||||
// that would be returned - the "deepest" route - and that is the route we want to cache, *not* the
|
||||
// longer one - so make sure we don't cache the wrong route
|
||||
|
||||
var deepest = DomainHelper.ExistsDomainInPath(_domainCache.GetAll(false), content.Path, domainRootNodeId) == false;
|
||||
|
||||
if (deepest)
|
||||
_routesCache.Store(content.Id, route);
|
||||
}
|
||||
|
||||
public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null)
|
||||
{
|
||||
return GetByRoute(PreviewDefault, route, hideTopLevelNode);
|
||||
@@ -120,11 +124,35 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
// else actually determine the route
|
||||
route = DetermineRouteById(preview, contentId);
|
||||
|
||||
// cache if we have a route and not previewing
|
||||
if (route != null && preview == false)
|
||||
// node not found
|
||||
if (route == null)
|
||||
return null;
|
||||
|
||||
// find the content back, detect routes collisions: we should find ourselves back,
|
||||
// else it means that another content with "higher priority" is sharing the same route.
|
||||
// perf impact:
|
||||
// - non-colliding, adds one complete "by route" lookup, only on the first time a url is computed (then it's cached anyways)
|
||||
// - colliding, adds one "by route" lookup, the first time the url is computed, then one dictionary looked each time it is computed again
|
||||
// assuming no collisions, the impact is one complete "by route" lookup the first time each url is computed
|
||||
var loopId = preview ? 0 : (_routesCache?.GetNodeId(route) ?? 0); // might be cached already in case of collision
|
||||
if (loopId == 0)
|
||||
{
|
||||
var content = DetermineIdByRoute(preview, route, GlobalSettings.HideTopLevelNodeFromPath);
|
||||
|
||||
// add the other route to cache so next time we have it already
|
||||
if (content != null && preview == false)
|
||||
AddToCacheIfDeepestRoute(content, route);
|
||||
|
||||
loopId = content?.Id ?? 0; // though... 0 here would be quite weird?
|
||||
}
|
||||
|
||||
// cache if we have a route and not previewing and it's not a colliding route
|
||||
// (the result of DetermineRouteById is always the deepest route)
|
||||
if (/*route != null &&*/ preview == false && loopId == contentId)
|
||||
_routesCache?.Store(contentId, route);
|
||||
|
||||
return route;
|
||||
// return route if no collision, else report collision
|
||||
return loopId == contentId ? route : ("err/" + loopId);
|
||||
}
|
||||
|
||||
public string GetRouteById(int contentId)
|
||||
|
||||
Reference in New Issue
Block a user