What are the options for fast traversal of the content document tree outside of the request pipeline?
I have a need to add new fields to a Lucene index inside Examine's GatheringNodeData event, using content obtained from properties of another document, the id of which is obtained from the value of a content picker property belonging to the node that's being indexed.
From what I've read, we can't use IPublishedContent for this, as IPublishedContent is only available within the request pipeline.
I assume the Content Service is available in this situation, but as I understand it the Content Service is very slow to access as it interrogates the database directly, and I'd need to do this for every document that is indexed.
One thing to note about that blog post, if the UmbracoContext is available, then if you are only retrieving content, then you don't need UmbracoHelper ... you can use the ContentCache directly.
e.g.
var node = UmbracoContext.Current.ContentCache.GetById(1234);
I was debugging at the time, so maybe UmbracoContext can timeout or something, or crash out when debugging in Visual Studio.
After restarting the web application I didn't get the error. I'll do some more testing and see if it crops up again by monitoring the log files, but I'm worried Staheri's solution might be flakey.
Here's a more detailed snapshot of the error from Umbraco_TraceLog.txt:
System.NullReferenceException: Object reference not set to an instance of an object.
at Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks(String text, Boolean preview)
at Umbraco.Web.PropertyEditors.ValueConverters.TextStringValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview)
at Umbraco.Core.Models.PublishedContent.PublishedPropertyType.ConvertDataToSource(Object source, Boolean preview)
at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__1()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.get_Value()
at Umbraco.Web.PublishedPropertyExtension.GetValue[T](IPublishedProperty property, Boolean withDefaultValue, T defaultValue)
at Umbraco.Web.PublishedContentExtensions.GetPropertyValue[T](IPublishedContent content, String alias, Boolean recurse, Boolean withDefaultValue, T defaultValue)
at Umbraco.Web.PublishedContentExtensions.GetPropertyValue[T](IPublishedContent content, String alias)
I am running from Visual Studio in debug mode. I'll test on a live IIS site later today.
I had the same problem on a live site running in IIS (Umbraco v7.2.4).
I added the following to the start of the GatheringNodeData event and now it seems to be working okay:
if (UmbracoContext.Current == null)
{
var dummyContext = new HttpContextWrapper(new HttpContext(new SimpleWorkerRequest("/", string.Empty, new StringWriter())));
UmbracoContext.EnsureContext(
dummyContext,
ApplicationContext.Current,
new WebSecurity(dummyContext, ApplicationContext.Current),
false);
}
What are the options for fast traversal of the content document tree outside of the request pipeline?
I have a need to add new fields to a Lucene index inside Examine's GatheringNodeData event, using content obtained from properties of another document, the id of which is obtained from the value of a content picker property belonging to the node that's being indexed.
From what I've read, we can't use IPublishedContent for this, as IPublishedContent is only available within the request pipeline.
I assume the Content Service is available in this situation, but as I understand it the Content Service is very slow to access as it interrogates the database directly, and I'd need to do this for every document that is indexed.
Are there any other options?
Hi Mark,
There's a thread from last year that explores this topic...
https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/57892-IPublishedContent-and-GatheringNodeData
... with a link to a blog post about how to ensure the
UmbracoContext
andUmbracoHelper
, so you can get access to theIPublishedContent
nodes.http://staheri.com/my-blog/2015/march/custom-examine-indexing-using-umbraco-cache/
I hope this helps?
Cheers,
- Lee
One thing to note about that blog post, if the
UmbracoContext
is available, then if you are only retrieving content, then you don't needUmbracoHelper
... you can use theContentCache
directly.e.g.
Thanks @Lee
I'll do some testing early next week, and update you (and hopefully mark the solution) once I'm done.
Thanks, Mark
Hi @Lee
Unfortunately I've run straight into an issue where UmbracoContext.Current is null.
Accessing some properties on document types threw:
When I used the form:
or
Although, this seemed to work:
Go figure...
I was debugging at the time, so maybe UmbracoContext can timeout or something, or crash out when debugging in Visual Studio.
After restarting the web application I didn't get the error. I'll do some more testing and see if it crops up again by monitoring the log files, but I'm worried Staheri's solution might be flakey.
Here's a more detailed snapshot of the error from Umbraco_TraceLog.txt:
I am running from Visual Studio in debug mode. I'll test on a live IIS site later today.
I had the same problem on a live site running in IIS (Umbraco v7.2.4).
I added the following to the start of the GatheringNodeData event and now it seems to be working okay:
is working on a reply...