From 38c876bb5366a22ad6a0ea30ae265272ff817742 Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 16 Aug 2016 14:35:31 +0200 Subject: [PATCH] Revert "U4-8813 - bugfix" This reverts commit 95fb7f97d084f0e8a7fc438d9b56cb352b422c30. --- .../XmlPublishedCache/PublishedMediaCache.cs | 31 +++++++------------ .../Routing/RedirectTrackingEventHandler.cs | 8 ++--- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs index c6397e70bf..db2ca62794 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs @@ -4,7 +4,6 @@ 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; @@ -198,18 +197,18 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache { try { - // 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. + //first check in Examine as this is WAY faster + var criteria = searchProvider.CreateSearchCriteria("media"); - 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 result = searchProvider.Search(filter.Compile()).FirstOrDefault(); - if (result != null) return ConvertFromSearchResult(result); + var results = searchProvider.Search(filter.Compile()); + if (results.Any()) + { + return ConvertFromSearchResult(results.First()); + } } catch (FileNotFoundException ex) { @@ -221,23 +220,17 @@ 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 miss = Interlocked.CompareExchange(ref _examineIndexMiss, 0, 0); // volatile read - if (miss <= ExamineIndexMissMax && Interlocked.Increment(ref _examineIndexMiss) == ExamineIndexMissMax) - LogHelper.Warn("bam"); + + //var media = global::umbraco.library.GetMedia(id, false); + //return ConvertFromXPathNodeIterator(media, id); 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 f7b0b17584..59b004dc6b 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 + // prepare entities - remove chances of duplicates var entities = PrepareEntities(args.PublishedEntities); foreach (var entity in entities) @@ -206,12 +206,8 @@ 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.Where(x => x.HasIdentity).OrderBy(x => x.Level)) + foreach (var e in eventEntities.OrderBy(x => x.Level)) { var pathIds = e.Path.Split(',').Select(int.Parse); if (entities.Any(x => pathIds.Contains(x.Id))) continue;