From d38d7b1ff41d328571fa7b3cb70fdac76e2194dd Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Wed, 30 Jan 2013 07:59:03 +0600 Subject: [PATCH] Updates all code calling UnPublishSingleNode & UpdateDocumentCache to pass in the already existing Document object if there is one instead of the ID... this'll save a another ton of SQL calls. --- .../umbraco.presentation/content.cs | 30 ++++++++++--------- .../umbraco.presentation/library.cs | 21 ++++++++++--- .../umbraco.presentation/publishingService.cs | 2 +- .../Modules/CreateModule/CreateModule.cs | 2 +- .../umbraco/actions/publish.aspx.cs | 2 +- .../umbraco/channels/UmbracoMetaWeblogAPI.cs | 4 +-- .../umbraco/dialogs/moveOrCopy.aspx.cs | 4 +-- .../umbraco/dialogs/publish.aspx.cs | 6 ++-- .../umbraco/uQuery/DocumentExtensions.cs | 2 +- .../documents/documentService.cs | 8 ++--- 10 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/content.cs b/src/Umbraco.Web/umbraco.presentation/content.cs index ee5da1467f..5161c14119 100644 --- a/src/Umbraco.Web/umbraco.presentation/content.cs +++ b/src/Umbraco.Web/umbraco.presentation/content.cs @@ -580,40 +580,42 @@ namespace umbraco ThreadPool.QueueUserWorkItem(delegate { UpdateDocumentCache(documentId); }); } - - [Obsolete("Method obsolete in version 4.1 and later, please use ClearDocumentCache", true)] /// /// Clears the document cache async. /// /// The document id. + [Obsolete("Method obsolete in version 4.1 and later, please use ClearDocumentCache", true)] public virtual void ClearDocumentCacheAsync(int documentId) { ThreadPool.QueueUserWorkItem(delegate { ClearDocumentCache(documentId); }); } + public virtual void ClearDocumentCache(int documentId) + { + // Get the document + var d = new Document(documentId); + ClearDocumentCache(d); + } /// /// Clears the document cache and removes the document from the xml db cache. /// This means the node gets unpublished from the website. /// - /// The document id. - public virtual void ClearDocumentCache(int documentId) + /// The document + public virtual void ClearDocumentCache(Document doc) { - // Get the document - var d = new Document(documentId); - var e = new DocumentCacheEventArgs(); - FireBeforeClearDocumentCache(d, e); + FireBeforeClearDocumentCache(doc, e); if (!e.Cancel) { XmlNode x; // remove from xml db cache - d.XmlRemoveFromDB(); + doc.XmlRemoveFromDB(); // Check if node present, before cloning - x = XmlContentInternal.GetElementById(d.Id.ToString()); + x = XmlContentInternal.GetElementById(doc.Id.ToString()); if (x == null) return; @@ -626,7 +628,7 @@ namespace umbraco XmlDocument xmlContentCopy = CloneXmlDoc(XmlContentInternal); // Find the document in the xml cache - x = xmlContentCopy.GetElementById(d.Id.ToString()); + x = xmlContentCopy.GetElementById(doc.Id.ToString()); if (x != null) { // The document already exists in cache, so repopulate it @@ -639,17 +641,17 @@ namespace umbraco if (x != null) { // Run Handler - Action.RunActionHandlers(d, ActionUnPublish.Instance); + Action.RunActionHandlers(doc, ActionUnPublish.Instance); } // update sitemapprovider if (SiteMap.Provider is UmbracoSiteMapProvider) { var prov = (UmbracoSiteMapProvider)SiteMap.Provider; - prov.RemoveNode(d.Id); + prov.RemoveNode(doc.Id); } - FireAfterClearDocumentCache(d, e); + FireAfterClearDocumentCache(doc, e); } } diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index 8a78f77168..9a081380e3 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -187,9 +187,7 @@ namespace umbraco /// /// The Id of the Document to be unpublished public static void UnPublishSingleNode(int DocumentId) - { - - //PPH Added dispatcher support + { if (UmbracoSettings.UseDistributedCalls) dispatcher.Remove( new Guid("27ab3022-3dfa-47b6-9119-5945bc88fd66"), @@ -198,6 +196,21 @@ namespace umbraco content.Instance.ClearDocumentCache(DocumentId); } + /// + /// Unpublish a node, by removing it from the runtime xml index. Note, prior to this the Document should be + /// marked unpublished by setting the publish property on the document object to false + /// + /// The Document to be unpublished + public static void UnPublishSingleNode(Document document) + { + if (UmbracoSettings.UseDistributedCalls) + dispatcher.Remove( + new Guid("27ab3022-3dfa-47b6-9119-5945bc88fd66"), + document.Id); + else + content.Instance.ClearDocumentCache(document); + } + /// /// 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. @@ -219,7 +232,7 @@ namespace umbraco /// 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) + public static void UpdateDocumentCache(Document doc) { if (UmbracoSettings.UseDistributedCalls) dispatcher.Refresh( diff --git a/src/Umbraco.Web/umbraco.presentation/publishingService.cs b/src/Umbraco.Web/umbraco.presentation/publishingService.cs index f45c6d5916..163da00565 100644 --- a/src/Umbraco.Web/umbraco.presentation/publishingService.cs +++ b/src/Umbraco.Web/umbraco.presentation/publishingService.cs @@ -38,7 +38,7 @@ namespace umbraco.presentation d.ReleaseDate = DateTime.MinValue; //new DateTime(1, 1, 1); // Causes release date to be null d.Publish(d.User); - library.UpdateDocumentCache(d.Id); + library.UpdateDocumentCache(d); } catch(Exception ee) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/CreateModule/CreateModule.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/CreateModule/CreateModule.cs index 18b0e22a72..fd353d09cc 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/CreateModule/CreateModule.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/CreateModule/CreateModule.cs @@ -132,7 +132,7 @@ namespace umbraco.presentation.LiveEditing.Modules.CreateModule DocumentType typeToCreate = new DocumentType(Convert.ToInt32(m_AllowedDocTypesDropdown.SelectedValue)); Document newDoc = Document.MakeNew(m_NameTextBox.Text, typeToCreate, new global::umbraco.BusinessLogic.User(userid), (int)UmbracoContext.Current.PageId); newDoc.Publish(new global::umbraco.BusinessLogic.User(userid)); - library.UpdateDocumentCache(newDoc.Id); + library.UpdateDocumentCache(newDoc); Page.Response.Redirect(library.NiceUrl(newDoc.Id), false); break; } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/actions/publish.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/actions/publish.aspx.cs index 94c88425ac..d58e002785 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/actions/publish.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/actions/publish.aspx.cs @@ -39,7 +39,7 @@ namespace umbraco.presentation.actions confirm.Visible = false; d.Publish(getUser()); - library.UpdateDocumentCache(d.Id); + library.UpdateDocumentCache(d); deleted.Text = ui.Text("editContentPublishedHeader") + " ('" + d.Text + "') " + ui.Text("editContentPublishedText") + "

" + ui.Text("view") + " " + d.Text + ""; } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/channels/UmbracoMetaWeblogAPI.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/channels/UmbracoMetaWeblogAPI.cs index afe99ac4d2..c1089d77be 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/channels/UmbracoMetaWeblogAPI.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/channels/UmbracoMetaWeblogAPI.cs @@ -84,7 +84,7 @@ namespace umbraco.presentation.channels if (publish) { doc.Publish(new User(username)); - library.UpdateDocumentCache(doc.Id); + library.UpdateDocumentCache(doc); } return true; } @@ -403,7 +403,7 @@ namespace umbraco.presentation.channels if (publish) { doc.Publish(new User(username)); - library.UpdateDocumentCache(doc.Id); + library.UpdateDocumentCache(doc); } return doc.Id.ToString(); } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.cs index b4e966021c..3bd289e1e0 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.cs @@ -152,7 +152,7 @@ namespace umbraco.dialogs if (cd.Published) { cd.Publish(new umbraco.BusinessLogic.User(0)); //using library.publish to support load balancing. - umbraco.library.UpdateDocumentCache(cd.Id); + umbraco.library.UpdateDocumentCache(cd); if (cd.HasChildren) { @@ -299,7 +299,7 @@ namespace umbraco.dialogs d.Publish(new umbraco.BusinessLogic.User(0)); //using library.publish to support load balancing. //umbraco.library.PublishSingleNode(d.Id); - umbraco.library.UpdateDocumentCache(d.Id); + umbraco.library.UpdateDocumentCache(d); //PPH added handling of load balanced moving of multiple nodes... if (d.HasChildren) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/publish.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/publish.aspx.cs index 9feee1ecd9..7d05314df7 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/publish.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/publish.aspx.cs @@ -92,7 +92,7 @@ namespace umbraco.dialogs { if (doc.Published) { - library.UpdateDocumentCache(doc.Id); + library.UpdateDocumentCache(doc); } } @@ -116,7 +116,7 @@ namespace umbraco.dialogs { if (d.PublishWithResult(base.getUser())) { - library.UpdateDocumentCache(d.Id); + library.UpdateDocumentCache(d); feedbackMsg.type = umbraco.uicontrols.Feedback.feedbacktype.success; feedbackMsg.Text = ui.Text("publish", "nodePublish", d.Text, base.getUser()) + "

" + ui.Text("closeThisWindow") + ""; } @@ -141,7 +141,7 @@ namespace umbraco.dialogs { // Needed for supporting distributed calls if (UmbracoSettings.UseDistributedCalls) - library.UpdateDocumentCache(d.Id); + library.UpdateDocumentCache(d); else documents.Add(d); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/DocumentExtensions.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/DocumentExtensions.cs index 7c7b17c3a2..de897b6209 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/DocumentExtensions.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/DocumentExtensions.cs @@ -250,7 +250,7 @@ namespace umbraco } } - library.UpdateDocumentCache(document.Id); + library.UpdateDocumentCache(document); return document; } diff --git a/src/umbraco.webservices/documents/documentService.cs b/src/umbraco.webservices/documents/documentService.cs index caea93c368..cea5a61d7e 100644 --- a/src/umbraco.webservices/documents/documentService.cs +++ b/src/umbraco.webservices/documents/documentService.cs @@ -246,13 +246,13 @@ namespace umbraco.webservices.documents case documentCarrier.EPublishAction.Publish: if (doc.PublishWithResult(user)) { - umbraco.library.UpdateDocumentCache(doc.Id); + umbraco.library.UpdateDocumentCache(doc); } break; case documentCarrier.EPublishAction.Unpublish: if (doc.PublishWithResult(user)) { - umbraco.library.UnPublishSingleNode(doc.Id); + umbraco.library.UnPublishSingleNode(doc); } break; case documentCarrier.EPublishAction.Ignore: @@ -260,14 +260,14 @@ namespace umbraco.webservices.documents { if (doc.PublishWithResult(user)) { - umbraco.library.UpdateDocumentCache(doc.Id); + umbraco.library.UpdateDocumentCache(doc); } } else { if (doc.PublishWithResult(user)) { - umbraco.library.UpdateDocumentCache(doc.Id); + umbraco.library.UpdateDocumentCache(doc); } } break;