diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs index 2a3a6efca2..2dcbe06458 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs @@ -52,9 +52,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings [ConfigurationProperty("PreviewBadge")] internal InnerTextConfigurationElement PreviewBadge => GetOptionalTextElement("PreviewBadge", DefaultPreviewBadge); - [ConfigurationProperty("UmbracoLibraryCacheDuration")] - internal InnerTextConfigurationElement UmbracoLibraryCacheDuration => GetOptionalTextElement("UmbracoLibraryCacheDuration", 1800); - [ConfigurationProperty("MacroErrors")] internal InnerTextConfigurationElement MacroErrors => GetOptionalTextElement("MacroErrors", MacroErrorBehaviour.Inline); @@ -121,8 +118,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings string IContentSection.PreviewBadge => PreviewBadge; - int IContentSection.UmbracoLibraryCacheDuration => UmbracoLibraryCacheDuration; - MacroErrorBehaviour IContentSection.MacroErrorBehaviour => MacroErrors; IEnumerable IContentSection.DisallowedUploadFiles => DisallowedUploadFiles; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IContentSection.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IContentSection.cs index 176b53fdcb..7f6f57f4cf 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IContentSection.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/IContentSection.cs @@ -43,8 +43,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings string PreviewBadge { get; } - int UmbracoLibraryCacheDuration { get; } - MacroErrorBehaviour MacroErrorBehaviour { get; } IEnumerable DisallowedUploadFiles { get; } diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/ContentElementTests.cs b/src/Umbraco.Tests/Configurations/UmbracoSettings/ContentElementTests.cs index f360262cd0..fe32a43cc9 100644 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/ContentElementTests.cs +++ b/src/Umbraco.Tests/Configurations/UmbracoSettings/ContentElementTests.cs @@ -147,11 +147,6 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings Assert.IsTrue(SettingsSection.Content.PreviewBadge == @"In Preview Mode - click to end"); } [Test] - public void UmbracoLibraryCacheDuration() - { - Assert.IsTrue(SettingsSection.Content.UmbracoLibraryCacheDuration == 1800); - } - [Test] public void ResolveUrlsFromTextString() { Assert.IsFalse(SettingsSection.Content.ResolveUrlsFromTextString); diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.config b/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.config index 4541632264..5373afd1b5 100644 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.config +++ b/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.config @@ -77,10 +77,6 @@ In Preview Mode - click to end]]> - - - 1800 - - - 1800 diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs index f73e09dc2d..20d575c896 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs @@ -493,69 +493,88 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache /// private IEnumerable GetChildrenMedia(int parentId, XPathNavigator xpath = null) { - //if there is no navigator, try examine first, then re-look it up - if (xpath == null) + if (xpath != null) { - var searchProvider = GetSearchProviderSafe(); + return ToIPublishedContent(parentId, xpath); + } - if (searchProvider != null) + var searchProvider = GetSearchProviderSafe(); + + if (searchProvider != null) + { + try { - try + //first check in Examine as this is WAY faster + var criteria = searchProvider.CreateCriteria("media"); + + var filter = criteria.ParentId(parentId).Not().Field(UmbracoExamineIndexer.IndexPathFieldName, "-1,-21,".MultipleCharacterWildcard()); + //the above filter will create a query like this, NOTE: That since the use of the wildcard, it automatically escapes it in Lucene. + //+(+parentId:3113 -__Path:-1,-21,*) +__IndexType:media + + // sort with the Sort field (updated for 8.0) + var results = searchProvider.Search( + filter.And().OrderBy(new SortableField("sortOrder", SortType.Int)).Compile()); + + if (results.Any()) { - //first check in Examine as this is WAY faster - var criteria = searchProvider.CreateCriteria("media"); - - var filter = criteria.ParentId(parentId).Not().Field(UmbracoExamineIndexer.IndexPathFieldName, "-1,-21,".MultipleCharacterWildcard()); - //the above filter will create a query like this, NOTE: That since the use of the wildcard, it automatically escapes it in Lucene. - //+(+parentId:3113 -__Path:-1,-21,*) +__IndexType:media - - // sort with the Sort field (updated for 8.0) - var results = searchProvider.Search( - filter.And().OrderBy(new SortableField("sortOrder", SortType.Int)).Compile()); - - if (results.Any()) + // var medias = results.Select(ConvertFromSearchResult); + var medias = results.Select(x => { - // var medias = results.Select(ConvertFromSearchResult); - var medias = results.Select(x => - { - int nid; - if (int.TryParse(x["__NodeId"], out nid) == false && int.TryParse(x["NodeId"], out nid) == false) - throw new Exception("Failed to extract NodeId from search result."); - var cacheValues = GetCacheValues(nid, id => ConvertFromSearchResult(x)); - return CreateFromCacheValues(cacheValues); - }); + int nid; + if (int.TryParse(x["__NodeId"], out nid) == false && int.TryParse(x["NodeId"], out nid) == false) + throw new Exception("Failed to extract NodeId from search result."); + var cacheValues = GetCacheValues(nid, id => ConvertFromSearchResult(x)); + return CreateFromCacheValues(cacheValues); + }); - return medias; - } - - //if there's no result then return null. Previously we defaulted back to library.GetMedia below - //but this will always get called for when we are getting descendents since many items won't have - //children and then we are hitting the database again! - //So instead we're going to rely on Examine to have the correct results like it should. - return Enumerable.Empty(); + return medias; } - catch (FileNotFoundException) - { - //Currently examine is throwing FileNotFound exceptions when we have a loadbalanced filestore and a node is published in umbraco - //See this thread: http://examine.cdodeplex.com/discussions/264341 - //Catch the exception here for the time being, and just fallback to GetMedia - } - } - //falling back to get media - - var media = library.GetMedia(parentId, true); - if (media?.Current != null) - { - xpath = media.Current; - } - else - { + //if there's no result then return null. Previously we defaulted back to library.GetMedia below + //but this will always get called for when we are getting descendents since many items won't have + //children and then we are hitting the database again! + //So instead we're going to rely on Examine to have the correct results like it should. return Enumerable.Empty(); } + catch (FileNotFoundException) + { + //Currently examine is throwing FileNotFound exceptions when we have a loadbalanced filestore and a node is published in umbraco + //See this thread: http://examine.cdodeplex.com/discussions/264341 + //Catch the exception here for the time being, and just fallback to GetMedia + } } + //falling back to get media + var media = Current.Services.MediaService.GetById(parentId); + if (media == null) + { + return Enumerable.Empty(); + } + + var serialized = EntityXmlSerializer.Serialize( + Current.Services.MediaService, + Current.Services.DataTypeService, + Current.Services.UserService, + Current.Services.LocalizationService, + Current.UrlSegmentProviders, + media, + true); + + var mediaIterator = serialized.CreateNavigator().Select("/"); + + if (mediaIterator.Current == null) + { + return Enumerable.Empty(); + } + xpath = mediaIterator.Current; + + return ToIPublishedContent(parentId, xpath); + } + + + internal IEnumerable ToIPublishedContent(int parentId, XPathNavigator xpath) + { var mediaList = new List(); // this is so bad, really @@ -578,32 +597,10 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache mediaList.Add(CreateFromCacheValues(cacheValues)); } - ////The xpath might be the whole xpath including the current ones ancestors so we need to select the current node - //var item = xpath.Select("//*[@id='" + parentId + "']"); - //if (item.Current == null) - //{ - // return Enumerable.Empty(); - //} - //var children = item.Current.SelectChildren(XPathNodeType.Element); - - //foreach(XPathNavigator x in children) - //{ - // //NOTE: I'm not sure why this is here, it is from legacy code of ExamineBackedMedia, but - // // will leave it here as it must have done something! - // if (x.Name != "contents") - // { - // //make sure it's actually a node, not a property - // if (!string.IsNullOrEmpty(x.GetAttribute("path", "")) && - // !string.IsNullOrEmpty(x.GetAttribute("id", ""))) - // { - // mediaList.Add(ConvertFromXPathNavigator(x)); - // } - // } - //} - return mediaList; } + internal void Resync() { // clear recursive properties cached by XmlPublishedContent.GetProperty diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs deleted file mode 100644 index d76b4066f6..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Xml.Linq; -using System.Xml.XPath; -using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; -using Umbraco.Core.Services; -using Umbraco.Web.Composing; - -namespace umbraco -{ - /// - /// Function library for umbraco. Includes various helper-methods and methods to - /// save and load data from umbraco. - /// - /// Especially usefull in XSLT where any of these methods can be accesed using the umbraco.library name-space. Example: - /// <xsl:value-of select="umbraco.library:NiceUrl(@id)"/> - /// - [Obsolete("v8.kill.kill")] - public class library - { - /// - /// Get a media object as an xml object - /// - /// The identifier of the media object to be returned - /// If true, children of the media object is returned - /// An umbraco xml node of the media (same format as a document node) - public static XPathNodeIterator GetMedia(int MediaId, bool deep) - { - try - { - if (UmbracoConfig.For.UmbracoSettings().Content.UmbracoLibraryCacheDuration > 0) - { - var xml = Current.ApplicationCache.RuntimeCache.GetCacheItem( - $"{CacheKeys.MediaCacheKey}_{MediaId}_{deep}", - timeout: TimeSpan.FromSeconds(UmbracoConfig.For.UmbracoSettings().Content.UmbracoLibraryCacheDuration), - getCacheItem: () => GetMediaDo(MediaId, deep).Item1); - - if (xml != null) - { - //returning the root element of the Media item fixes the problem - return xml.CreateNavigator().Select("/"); - } - - } - else - { - var xml = GetMediaDo(MediaId, deep).Item1; - - //returning the root element of the Media item fixes the problem - return xml.CreateNavigator().Select("/"); - } - } - catch(Exception ex) - { - Current.Logger.Error("An error occurred looking up media", ex); - } - - Current.Logger.Debug(() => $"No media result for id {MediaId}"); - - var errorXml = new XElement("error", string.Format("No media is maching '{0}'", MediaId)); - return errorXml.CreateNavigator().Select("/"); - } - - - private static Tuple GetMediaDo(int mediaId, bool deep) - { - var media = Current.Services.MediaService.GetById(mediaId); - if (media == null) return null; - - var serialized = EntityXmlSerializer.Serialize( - Current.Services.MediaService, - Current.Services.DataTypeService, - Current.Services.UserService, - Current.Services.LocalizationService, - Current.UrlSegmentProviders, - media, - deep); - return Tuple.Create(serialized, media.Path); - } - } -}