Fixing SELECT N+1 when listing blog archives

WORST SELECT N+1 EVER and it seems I wrote the code :/
This commit is contained in:
Sebastien Ros 2013-10-18 15:10:08 -07:00
parent a62f0281eb
commit 0c9e4e1224
2 changed files with 6 additions and 1 deletions

View File

@ -148,6 +148,10 @@
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
<Name>Orchard.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Autoroute\Orchard.Autoroute.csproj">
<Project>{66fccd76-2761-47e3-8d11-b45d0001ddaa}</Project>
<Name>Orchard.Autoroute</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.ContentPicker\Orchard.ContentPicker.csproj">
<Project>{f301ef7d-f19c-4d83-aa94-cb64f29c037d}</Project>
<Name>Orchard.ContentPicker</Name>

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Orchard.Autoroute.Models;
using Orchard.Blogs.Models;
using Orchard.Blogs.Routing;
using Orchard.ContentManagement;
@ -19,7 +20,7 @@ namespace Orchard.Blogs.Services {
}
public BlogPart Get(string path) {
return _contentManager.Query<BlogPart>().List().FirstOrDefault(rr => rr.As<IAliasAspect>().Path == path);
return _contentManager.Query<AutoroutePart, AutoroutePartRecord>().Where(r => r.DisplayAlias == path).ForPart<BlogPart>().Slice(0, 1).FirstOrDefault();
}
public ContentItem Get(int id, VersionOptions versionOptions) {