diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs index db2ca62794..c6397e70bf 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs @@ -4,6 +4,7 @@ using System.Collections.ObjectModel; using System.Configuration; using System.IO; using System.Linq; +using System.Threading; using System.Xml.XPath; using Examine; using Examine.LuceneEngine.SearchCriteria; @@ -197,18 +198,18 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache { try { - //first check in Examine as this is WAY faster - var criteria = searchProvider.CreateSearchCriteria("media"); + // first check in Examine as this is WAY faster + // + // the filter will create a query like this: + // +(+__NodeId:3113 -__Path:-1,-21,*) +__IndexType:media + // + // note that since the use of the wildcard, it automatically escapes it in Lucene. + var criteria = searchProvider.CreateSearchCriteria("media"); var filter = criteria.Id(id).Not().Field(UmbracoContentIndexer.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. - //+(+__NodeId:3113 -__Path:-1,-21,*) +__IndexType:media - var results = searchProvider.Search(filter.Compile()); - if (results.Any()) - { - return ConvertFromSearchResult(results.First()); - } + var result = searchProvider.Search(filter.Compile()).FirstOrDefault(); + if (result != null) return ConvertFromSearchResult(result); } catch (FileNotFoundException ex) { @@ -220,17 +221,23 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache } } + // this is annoying as it can flood the log in case of eg a media picker referencing a media + // that has been deleted, hence is not in the Examine index anymore (for a good reason) - yet + // it can also indicate that the Examine index is corrupted and would need to be rebuilt. LogHelper.Warn( "Could not retrieve media {0} from Examine index, reverting to looking up media via legacy library.GetMedia method", () => id); - - //var media = global::umbraco.library.GetMedia(id, false); - //return ConvertFromXPathNodeIterator(media, id); + var miss = Interlocked.CompareExchange(ref _examineIndexMiss, 0, 0); // volatile read + if (miss <= ExamineIndexMissMax && Interlocked.Increment(ref _examineIndexMiss) == ExamineIndexMissMax) + LogHelper.Warn("bam"); var media = ApplicationContext.Current.Services.MediaService.GetById(id); return media == null ? null : ConvertFromIMedia(media); } + private const int ExamineIndexMissMax = 10; + private int _examineIndexMiss; + internal CacheValues ConvertFromXPathNodeIterator(XPathNodeIterator media, int id) { if (media != null && media.Current != null) diff --git a/src/Umbraco.Web/Routing/RedirectTrackingEventHandler.cs b/src/Umbraco.Web/Routing/RedirectTrackingEventHandler.cs index 59b004dc6b..f7b0b17584 100644 --- a/src/Umbraco.Web/Routing/RedirectTrackingEventHandler.cs +++ b/src/Umbraco.Web/Routing/RedirectTrackingEventHandler.cs @@ -155,7 +155,7 @@ namespace Umbraco.Web.Routing var contentCache = GetPublishedCache(); if (contentCache == null) return; - // prepare entities - remove chances of duplicates + // prepare entities var entities = PrepareEntities(args.PublishedEntities); foreach (var entity in entities) @@ -206,8 +206,12 @@ namespace Umbraco.Web.Routing private static IEnumerable PrepareEntities(IEnumerable eventEntities) { + // prepare entities + // - exclude entities without an identity (new entities) + // - exclude duplicates (in case publishing a parent and its children) + var entities = new List(); - foreach (var e in eventEntities.OrderBy(x => x.Level)) + foreach (var e in eventEntities.Where(x => x.HasIdentity).OrderBy(x => x.Level)) { var pathIds = e.Path.Split(',').Select(int.Parse); if (entities.Any(x => pathIds.Contains(x.Id))) continue;