From 2fc0fe574b8b9c4c1361cf8f7f3fae1a506ebf61 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Sun, 2 Sep 2012 07:35:57 +0700 Subject: [PATCH] Fixed XmlDocument GetProperty to check for user properties 'invariantly'. Added a method on content to remove the file persistence queue just before it's written based on the module, this should hopefully speed things up and fix some potential issues. Added an overloaded method on library for UpdateDocumentCache which should save on a few dozen sql calls when publishing a node since we already have the Document object reference yet we were looking it up again for no reason. --- src/Umbraco.Web/Models/XmlDocument.cs | 3 +- src/Umbraco.Web/UmbracoModule.cs | 1 + .../umbraco.presentation/content.cs | 14 ++++++-- .../umbraco.presentation/library.cs | 34 ++++++++++++++----- .../umbraco/editContent.aspx.cs | 2 +- 5 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Web/Models/XmlDocument.cs b/src/Umbraco.Web/Models/XmlDocument.cs index 87d9cafeca..cf782d642a 100644 --- a/src/Umbraco.Web/Models/XmlDocument.cs +++ b/src/Umbraco.Web/Models/XmlDocument.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Xml; using System.Xml.Serialization; using System.Xml.XPath; +using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Models; @@ -263,7 +264,7 @@ namespace Umbraco.Web.Models public IDocumentProperty GetProperty(string alias) { - return Properties.FirstOrDefault(p => p.Alias == alias); + return Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias)); } private void InitializeStructure() diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index 7e5b6f117a..8a8e4731fc 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -164,6 +164,7 @@ namespace Umbraco.Web { if (content.Instance.IsXmlQueuedForPersistenceToFile) { + content.Instance.RemoveXmlFilePersistenceQueue(); content.Instance.PersistXmlToFile(); } } diff --git a/src/Umbraco.Web/umbraco.presentation/content.cs b/src/Umbraco.Web/umbraco.presentation/content.cs index 60e24cabd4..7372bc41d3 100644 --- a/src/Umbraco.Web/umbraco.presentation/content.cs +++ b/src/Umbraco.Web/umbraco.presentation/content.cs @@ -896,6 +896,16 @@ namespace umbraco internal const string PersistenceFlagContextKey = "vnc38ykjnkjdnk2jt98ygkxjng"; + /// + /// Removes the flag that queues the file for persistence + /// + internal void RemoveXmlFilePersistenceQueue() + { + HttpContext.Current.Application.Lock(); + HttpContext.Current.Application[PersistenceFlagContextKey] = null; + HttpContext.Current.Application.UnLock(); + } + internal bool IsXmlQueuedForPersistenceToFile { get @@ -915,9 +925,7 @@ namespace umbraco } else { - HttpContext.Current.Application.Lock(); - HttpContext.Current.Application[PersistenceFlagContextKey] = null; - HttpContext.Current.Application.UnLock(); + RemoveXmlFilePersistenceQueue(); } } catch diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index f9b23f0b21..398e313145 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -191,17 +191,33 @@ namespace umbraco /// Publishes a Document by adding it to the runtime xml index. Note, prior to this the Document should be /// marked published by calling Publish(User u) on the document object. /// - /// The Id of the Document to be published - public static void UpdateDocumentCache(int DocumentId) + /// The Id of the Document to be published + public static void UpdateDocumentCache(int documentId) { - if (UmbracoSettings.UseDistributedCalls) - dispatcher.Refresh( - new Guid("27ab3022-3dfa-47b6-9119-5945bc88fd66"), - DocumentId); - else - content.Instance.UpdateDocumentCache(DocumentId); + var d = new Document(documentId); + UpdateDocumentCache(d); } + /// + /// Publishes a Document by adding it to the runtime xml index. Note, prior to this the Document should be + /// marked published by calling Publish(User u) on the document object. + /// + /// + /// + /// NOTE: This method was created because before it was always calling the method with the documentId as a parameter + /// which means we have to re-look up the document in the db again when we already have it, this should save on a few + /// dozen sql calls when publishing. + /// + internal static void UpdateDocumentCache(Document doc) + { + if (UmbracoSettings.UseDistributedCalls) + dispatcher.Refresh( + new Guid("27ab3022-3dfa-47b6-9119-5945bc88fd66"), + doc.Id); + else + content.Instance.UpdateDocumentCache(doc); + } + /// /// Publishes the single node, this method is obsolete @@ -1563,6 +1579,8 @@ namespace umbraco } } + //TODO: WTF, why is this here? This won't matter if there's an UmbracoContext or not, it will call the same underlying method! + // only difference is that the UmbracoContext way will check if its in preview mode. private static XmlDocument GetThreadsafeXmlDocument() { return UmbracoContext.Current != null diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs index 1f50ddff3b..3c13c92cc5 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs @@ -315,7 +315,7 @@ namespace umbraco.cms.presentation { ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editContentPublishedHeader", null), ui.Text("speechBubbles", "editContentPublishedText", null)); - library.UpdateDocumentCache(_document.Id); + library.UpdateDocumentCache(_document); BusinessLogic.Log.Add(BusinessLogic.LogTypes.Publish, base.getUser(), _document.Id, ""); littPublishStatus.Text = ui.Text("content", "lastPublished", base.getUser()) + ": " + _document.VersionDate.ToString() + "
";