mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Improving path resolution performance
This commit is contained in:
@@ -16,7 +16,11 @@ namespace Orchard.Autoroute {
|
||||
.Attachable()
|
||||
.WithDescription("Adds advanced url configuration options to your content type to completely customize the url pattern for a content item."));
|
||||
|
||||
return 2;
|
||||
SchemaBuilder.AlterTable("AutoroutePartRecord", table => table
|
||||
.CreateIndex("IDX_AutoroutePartRecord_DisplayAlias", "DisplayAlias")
|
||||
);
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int UpdateFrom1() {
|
||||
@@ -24,5 +28,14 @@ namespace Orchard.Autoroute {
|
||||
.WithDescription("Adds advanced url configuration options to your content type to completely customize the url pattern for a content item."));
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int UpdateFrom2() {
|
||||
|
||||
SchemaBuilder.AlterTable("AutoroutePartRecord", table => table
|
||||
.CreateIndex("IDX_AutoroutePartRecord_DisplayAlias", "DisplayAlias")
|
||||
);
|
||||
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,20 +1,30 @@
|
||||
using System.Linq;
|
||||
using Orchard.Autoroute.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
|
||||
namespace Orchard.Autoroute.Services {
|
||||
public class PathResolutionService : IPathResolutionService {
|
||||
private readonly IContentManager _contentManager;
|
||||
IRepository<AutoroutePartRecord> _autorouteRepository;
|
||||
|
||||
public PathResolutionService(IContentManager contentManager) {
|
||||
public PathResolutionService(
|
||||
IRepository<AutoroutePartRecord> autorouteRepository,
|
||||
IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_autorouteRepository = autorouteRepository;
|
||||
}
|
||||
|
||||
public AutoroutePart GetPath(string path) {
|
||||
return _contentManager.Query<AutoroutePart, AutoroutePartRecord>()
|
||||
.Where(part => part.DisplayAlias == path)
|
||||
.Slice(0, 1)
|
||||
.FirstOrDefault();
|
||||
var autorouteRecord = _autorouteRepository.Table
|
||||
.Where(part => part.DisplayAlias == path && part.ContentItemVersionRecord.Latest && part.ContentItemVersionRecord.Published)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (autorouteRecord == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _contentManager.Get(autorouteRecord.Id).As<AutoroutePart>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Autoroute.Models;
|
||||
using Orchard.Autoroute.Services;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Caching;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Title.Models;
|
||||
using Orchard.Environment.Configuration;
|
||||
@@ -17,19 +19,33 @@ namespace Orchard.Blogs.Services {
|
||||
private readonly ShellSettings _shellSettings;
|
||||
private readonly IShellDescriptorManager _shellDescriptorManager;
|
||||
private readonly HashSet<int> _processedBlogParts = new HashSet<int>();
|
||||
IPathResolutionService _pathResolutionService;
|
||||
|
||||
public BlogService(
|
||||
IContentManager contentManager,
|
||||
IProcessingEngine processingEngine,
|
||||
ShellSettings shellSettings,
|
||||
IShellDescriptorManager shellDescriptorManager) {
|
||||
IShellDescriptorManager shellDescriptorManager,
|
||||
IPathResolutionService pathResolutionService) {
|
||||
_contentManager = contentManager;
|
||||
_processingEngine = processingEngine;
|
||||
_shellSettings = shellSettings;
|
||||
_shellDescriptorManager = shellDescriptorManager;
|
||||
_pathResolutionService = pathResolutionService;
|
||||
}
|
||||
|
||||
public BlogPart Get(string path) {
|
||||
return _contentManager.Query<AutoroutePart, AutoroutePartRecord>().Where(r => r.DisplayAlias == path).ForPart<BlogPart>().Slice(0, 1).FirstOrDefault();
|
||||
var blog = _pathResolutionService.GetPath(path);
|
||||
|
||||
if (blog == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!blog.Has<BlogPart>()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return blog.As<BlogPart>();
|
||||
}
|
||||
|
||||
public ContentItem Get(int id, VersionOptions versionOptions) {
|
||||
|
@@ -50,5 +50,19 @@ namespace Orchard.ContentManagement.DataMigrations {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int UpdateFrom2() {
|
||||
SchemaBuilder.AlterTable("ContentTypeRecord",
|
||||
table => table
|
||||
.CreateIndex("IDX_ContentType_Name", "Name")
|
||||
);
|
||||
|
||||
SchemaBuilder.AlterTable("ContentItemVersionRecord",
|
||||
table => table
|
||||
.CreateIndex("IDX_ContentItemVersionRecord_Published_Latest", "Published", "Latest")
|
||||
);
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user