From 0c9e4e12245f2438b3eeef1b0789873db3391352 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 18 Oct 2013 15:10:08 -0700 Subject: [PATCH 1/4] Fixing SELECT N+1 when listing blog archives WORST SELECT N+1 EVER and it seems I wrote the code :/ --- src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj | 4 ++++ src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj index 737ef18fc..37eb0d8ae 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj @@ -148,6 +148,10 @@ {9916839C-39FC-4CEB-A5AF-89CA7E87119F} Orchard.Core + + {66fccd76-2761-47e3-8d11-b45d0001ddaa} + Orchard.Autoroute + {f301ef7d-f19c-4d83-aa94-cb64f29c037d} Orchard.ContentPicker diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs index 4bfc517b0..6bc664967 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs @@ -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().List().FirstOrDefault(rr => rr.As().Path == path); + return _contentManager.Query().Where(r => r.DisplayAlias == path).ForPart().Slice(0, 1).FirstOrDefault(); } public ContentItem Get(int id, VersionOptions versionOptions) { From 2bdc29d8e98a8b196f96703a87b96b343e4451e7 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 18 Oct 2013 16:00:55 -0700 Subject: [PATCH 2/4] #20219: Fixing spam notifications Create(contentItem) actually publishes the content item. Create(ci, VersionOptions.Draft) won't Work Item: 20219 --- .../Modules/Orchard.Comments/Controllers/CommentController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Controllers/CommentController.cs b/src/Orchard.Web/Modules/Orchard.Comments/Controllers/CommentController.cs index bcafdb5ee..38c4fec44 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Controllers/CommentController.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Controllers/CommentController.cs @@ -30,7 +30,7 @@ namespace Orchard.Comments.Controllers { return this.RedirectLocal(returnUrl, "~/"); var comment = Services.ContentManager.New("Comment"); - Services.ContentManager.Create(comment); + Services.ContentManager.Create(comment, VersionOptions.Draft); var editorShape = Services.ContentManager.UpdateEditor(comment, this); From 15e4e27c46542266b9776531b2f8f6ad8749ea0f Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 18 Oct 2013 17:17:27 -0700 Subject: [PATCH 3/4] Optimizing user roles lazy loading --- .../Orchard.Roles/Handlers/UserRolesPartHandler.cs | 8 +++----- .../Modules/Orchard.Roles/Models/UserRolesPart.cs | 10 ++++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Handlers/UserRolesPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Roles/Handlers/UserRolesPartHandler.cs index af7fad3e8..958a9b05d 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Handlers/UserRolesPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Handlers/UserRolesPartHandler.cs @@ -13,11 +13,9 @@ namespace Orchard.Roles.Handlers { _userRolesRepository = userRolesRepository; Filters.Add(new ActivatingFilter("User")); - OnLoaded((context, userRoles) => { - userRoles.Roles = _userRolesRepository - .Fetch(x => x.UserId == context.ContentItem.Id) - .Select(x => x.Role.Name).ToList(); - }); + OnInitialized((context, userRoles) => userRoles._roles.Loader(value => _userRolesRepository + .Fetch(x => x.UserId == context.ContentItem.Id) + .Select(x => x.Role.Name).ToList())); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Models/UserRolesPart.cs b/src/Orchard.Web/Modules/Orchard.Roles/Models/UserRolesPart.cs index a9f9de831..9a9cd5241 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Models/UserRolesPart.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Models/UserRolesPart.cs @@ -1,12 +1,14 @@ using System.Collections.Generic; using Orchard.ContentManagement; +using Orchard.ContentManagement.Utilities; namespace Orchard.Roles.Models { public class UserRolesPart : ContentPart, IUserRoles { - public UserRolesPart() { - Roles = new List(); - } - public IList Roles { get; set; } + internal LazyField> _roles = new LazyField>(); + + public IList Roles { + get { return _roles.Value; } + } } } \ No newline at end of file From b2761dcd13334a2553f4b1b670bca0dd4a7d236a Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 18 Oct 2013 17:18:55 -0700 Subject: [PATCH 4/4] #19967: Fixing Menu import/export Work Item: 19967 --- src/Orchard.Web/Core/Navigation/Handlers/MenuHandler.cs | 8 -------- src/Orchard.Web/Core/Navigation/Migrations.cs | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Orchard.Web/Core/Navigation/Handlers/MenuHandler.cs b/src/Orchard.Web/Core/Navigation/Handlers/MenuHandler.cs index 285afd182..c190b019b 100644 --- a/src/Orchard.Web/Core/Navigation/Handlers/MenuHandler.cs +++ b/src/Orchard.Web/Core/Navigation/Handlers/MenuHandler.cs @@ -15,14 +15,6 @@ namespace Orchard.Core.Navigation.Handlers { _contentManager = contentManager; } - protected override void GetItemMetadata(GetContentItemMetadataContext context) { - if(context.ContentItem.ContentType != "Menu") { - return; - } - - context.Metadata.Identity.Add("name", context.ContentItem.As().Title); - } - protected override void Removing(RemoveContentContext context) { if (context.ContentItem.ContentType != "Menu") { return; diff --git a/src/Orchard.Web/Core/Navigation/Migrations.cs b/src/Orchard.Web/Core/Navigation/Migrations.cs index c46b38a2a..66e9d8f94 100644 --- a/src/Orchard.Web/Core/Navigation/Migrations.cs +++ b/src/Orchard.Web/Core/Navigation/Migrations.cs @@ -190,5 +190,13 @@ namespace Orchard.Core.Navigation { return 5; } + + public int UpdateFrom5() { + ContentDefinitionManager.AlterTypeDefinition("Menu", cfg => cfg + .WithPart("IdentityPart") + ); + + return 6; + } } } \ No newline at end of file