Fixes: U4-4624 Media cache hits the DB on every empty property, U4-4338 Umbraco fails to enumerate TypedMedia
This commit is contained in:
@@ -120,7 +120,12 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
try
|
||||
{
|
||||
//by default use the InternalSearcher
|
||||
return eMgr.IndexProviderCollection["InternalIndexer"];
|
||||
var indexer = eMgr.IndexProviderCollection["InternalIndexer"];
|
||||
if (indexer.IndexerData.IncludeNodeTypes.Any() || indexer.IndexerData.ExcludeNodeTypes.Any())
|
||||
{
|
||||
LogHelper.Warn<PublishedMediaCache>("The InternalIndexer for examine is configured incorrectly, it should not list any include/exclude node types or field names, it should simply be configured as: " + "<IndexSet SetName=\"InternalIndexSet\" IndexPath=\"~/App_Data/TEMP/ExamineIndexes/Internal/\" />");
|
||||
}
|
||||
return indexer;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -176,12 +181,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
return ConvertFromSearchResult(results.First());
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
//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
|
||||
//TODO: Need to fix examine in LB scenarios!
|
||||
LogHelper.Error<PublishedMediaCache>("Could not load data from Examine index for media", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,9 +262,9 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
if (xpath == null) throw new ArgumentNullException("xpath");
|
||||
|
||||
var values = new Dictionary<string, string> {{"nodeName", xpath.GetAttribute("nodeName", "")}};
|
||||
if (!UmbracoSettings.UseLegacyXmlSchema)
|
||||
if (UmbracoSettings.UseLegacyXmlSchema == false)
|
||||
{
|
||||
values.Add("nodeTypeAlias", xpath.Name);
|
||||
values["nodeTypeAlias"] = xpath.Name;
|
||||
}
|
||||
|
||||
var result = xpath.SelectChildren(XPathNodeType.Element);
|
||||
@@ -270,13 +276,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
//checking for duplicate keys because of the 'nodeTypeAlias' might already be added above.
|
||||
if (!values.ContainsKey(result.Current.Name))
|
||||
{
|
||||
values.Add(result.Current.Name, result.Current.Value);
|
||||
values[result.Current.Name] = result.Current.Value;
|
||||
}
|
||||
while (result.Current.MoveToNextAttribute())
|
||||
{
|
||||
if (!values.ContainsKey(result.Current.Name))
|
||||
{
|
||||
values.Add(result.Current.Name, result.Current.Value);
|
||||
values[result.Current.Name] = result.Current.Value;
|
||||
}
|
||||
}
|
||||
result.Current.MoveToParent();
|
||||
@@ -295,7 +301,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
value = result.Current.OuterXml;
|
||||
}
|
||||
}
|
||||
values.Add(result.Current.Name, value);
|
||||
values[result.Current.Name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,48 +325,25 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
/// <returns></returns>
|
||||
private IPublishedProperty GetProperty(DictionaryPublishedContent dd, string alias)
|
||||
{
|
||||
if (dd.LoadedFromExamine)
|
||||
{
|
||||
//if this is from Examine, lets check if the alias does not exist on the document
|
||||
if (dd.Properties.All(x => x.PropertyTypeAlias != alias))
|
||||
{
|
||||
//ok it doesn't exist, we might assume now that Examine didn't index this property because the index is not set up correctly
|
||||
//so before we go loading this from the database, we can check if the alias exists on the content type at all, this information
|
||||
//is cached so will be quicker to look up.
|
||||
if (dd.Properties.Any(x => x.PropertyTypeAlias == UmbracoContentIndexer.NodeTypeAliasFieldName))
|
||||
{
|
||||
// so in dd.Properties, there is an IPublishedProperty with property type alias "__NodeTypeAlias" and
|
||||
// that special property would contain the node type alias, which we use to get "aliases & names". That
|
||||
// special property is going to be a PropertyResult (with Value == DataValue) and we
|
||||
// want its value in the most simple way = it is OK to use DataValue here.
|
||||
var aliasesAndNames = ContentType.GetAliasesAndNames(dd.Properties.First(x => x.PropertyTypeAlias.InvariantEquals(UmbracoContentIndexer.NodeTypeAliasFieldName)).DataValue.ToString());
|
||||
if (aliasesAndNames != null)
|
||||
{
|
||||
if (!aliasesAndNames.ContainsKey(alias))
|
||||
{
|
||||
//Ok, now we know it doesn't exist on this content type anyways
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
//lets check if the alias does not exist on the document.
|
||||
//NOTE: Examine will not index empty values and we do not output empty XML Elements to the cache - either of these situations
|
||||
// would mean that the property is missing from the collection whether we are getting the value from Examine or from the library media cache.
|
||||
if (dd.Properties.All(x => x.PropertyTypeAlias != alias))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//if we've made it here, that means it does exist on the content type but not in examine, we'll need to query the db :(
|
||||
var media = global::umbraco.library.GetMedia(dd.Id, true);
|
||||
if (media != null && media.Current != null)
|
||||
{
|
||||
media.MoveNext();
|
||||
var mediaDoc = ConvertFromXPathNavigator(media.Current);
|
||||
return mediaDoc.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//We've made it here which means that the value is stored in the Examine index.
|
||||
//We are going to check for a special field however, that is because in some cases we store a 'Raw'
|
||||
//value in the index such as for xml/html.
|
||||
var rawValue = dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(UmbracoContentIndexer.RawFieldPrefix + alias));
|
||||
return rawValue
|
||||
?? dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias));
|
||||
if (dd.LoadedFromExamine)
|
||||
{
|
||||
//We are going to check for a special field however, that is because in some cases we store a 'Raw'
|
||||
//value in the index such as for xml/html.
|
||||
var rawValue = dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(UmbracoContentIndexer.RawFieldPrefix + alias));
|
||||
return rawValue
|
||||
?? dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias));
|
||||
}
|
||||
|
||||
//if its not loaded from examine, then just return the property
|
||||
return dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user