mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
@@ -83,11 +83,24 @@ namespace Orchard.Alias.Implementation.Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IDictionary<string, string> Get(string path) {
|
public IDictionary<string, string> Get(string path) {
|
||||||
return _aliasRepository
|
|
||||||
.Fetch(r => r.Path == path, o => o.Asc(r => r.Id), 0, 1)
|
// All aliases are already in memory, and updated. We don't need to query the
|
||||||
.Select(ToDictionary)
|
// database to lookup an alias by path.
|
||||||
.Select(item => item.Item3)
|
|
||||||
.SingleOrDefault();
|
AliasInfo alias;
|
||||||
|
|
||||||
|
// Optimized code path on Contents as it's the main provider of aliases
|
||||||
|
if (_aliasHolder.GetMap("Contents").TryGetAlias(path, out alias)) {
|
||||||
|
return alias.RouteValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var map in _aliasHolder.GetMaps()) {
|
||||||
|
if(map.TryGetAlias(path, out alias)) {
|
||||||
|
return alias.RouteValues;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(string path) {
|
public void Remove(string path) {
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
using Orchard.Alias;
|
using Orchard.Alias;
|
||||||
@@ -14,6 +15,8 @@ namespace Orchard.Autoroute.Services {
|
|||||||
private const string AliasSource = "Autoroute:Home";
|
private const string AliasSource = "Autoroute:Home";
|
||||||
private const string HomeAlias = "";
|
private const string HomeAlias = "";
|
||||||
|
|
||||||
|
private RouteValueDictionary _homeAliasRoute;
|
||||||
|
|
||||||
public HomeAliasService(IAliasService aliasService, IAliasHolder aliasHolder, IContentManager contentManager) {
|
public HomeAliasService(IAliasService aliasService, IAliasHolder aliasHolder, IContentManager contentManager) {
|
||||||
_aliasService = aliasService;
|
_aliasService = aliasService;
|
||||||
_aliasHolder = aliasHolder;
|
_aliasHolder = aliasHolder;
|
||||||
@@ -21,7 +24,11 @@ namespace Orchard.Autoroute.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RouteValueDictionary GetHomeRoute() {
|
public RouteValueDictionary GetHomeRoute() {
|
||||||
return _aliasService.Get(HomeAlias);
|
if(_homeAliasRoute == null) {
|
||||||
|
_homeAliasRoute = _aliasService.Get(HomeAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _homeAliasRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int? GetHomePageId(VersionOptions version = null) {
|
public int? GetHomePageId(VersionOptions version = null) {
|
||||||
@@ -40,7 +47,7 @@ namespace Orchard.Autoroute.Services {
|
|||||||
if (alias == null)
|
if (alias == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var homePage = _contentManager.Query<AutoroutePart, AutoroutePartRecord>(version).Where(x => x.DisplayAlias == alias).Slice(0, 1).SingleOrDefault();
|
var homePage = _contentManager.Query<AutoroutePart, AutoroutePartRecord>(version).Where(x => x.DisplayAlias == alias).Slice(0, 1).FirstOrDefault();
|
||||||
return homePage;
|
return homePage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +67,7 @@ namespace Orchard.Autoroute.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void PublishHomeAlias(RouteValueDictionary route) {
|
public void PublishHomeAlias(RouteValueDictionary route) {
|
||||||
|
_homeAliasRoute = route;
|
||||||
_aliasService.DeleteBySource(AliasSource);
|
_aliasService.DeleteBySource(AliasSource);
|
||||||
_aliasService.Set(HomeAlias, route, AliasSource);
|
_aliasService.Set(HomeAlias, route, AliasSource);
|
||||||
}
|
}
|
||||||
@@ -74,8 +82,16 @@ namespace Orchard.Autoroute.Services {
|
|||||||
if (map == null)
|
if (map == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var alias = map.GetAliases().FirstOrDefault(x => !String.IsNullOrWhiteSpace(x.Path));
|
var alias = map.GetAliases().FirstOrDefault(x => IsSameRoute(x.RouteValues, routeValues) && !String.IsNullOrWhiteSpace(x.Path));
|
||||||
return alias != null ? alias.Path : null;
|
return alias != null ? alias.Path : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsSameRoute(IDictionary<string,string> a, RouteValueDictionary b) {
|
||||||
|
if(a.Count != b.Count) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.Keys.All(x => a[x] == b[x].ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user