Merge branch 'v8hackathon-library-media-remove' of https://github.com/AnthonyCogworks/Umbraco-CMS into temp-2748
This commit is contained in:
@@ -493,69 +493,88 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
/// <returns></returns>
|
||||
private IEnumerable<IPublishedContent> 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<IPublishedContent>();
|
||||
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<IPublishedContent>();
|
||||
}
|
||||
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<IPublishedContent>();
|
||||
}
|
||||
|
||||
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<IPublishedContent>();
|
||||
}
|
||||
xpath = mediaIterator.Current;
|
||||
|
||||
return ToIPublishedContent(parentId, xpath);
|
||||
}
|
||||
|
||||
|
||||
internal IEnumerable<IPublishedContent> ToIPublishedContent(int parentId, XPathNavigator xpath)
|
||||
{
|
||||
var mediaList = new List<IPublishedContent>();
|
||||
|
||||
// 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<IPublishedContent>();
|
||||
//}
|
||||
//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
|
||||
|
||||
Reference in New Issue
Block a user