Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark 255 posts 612 karma points
    Oct 02, 2015 @ 15:24
    Mark
    0

    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?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Oct 02, 2015 @ 15:34
    Lee Kelleher
    1

    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 and UmbracoHelper, so you can get access to the IPublishedContent nodes.

    http://staheri.com/my-blog/2015/march/custom-examine-indexing-using-umbraco-cache/

    I hope this helps?

    Cheers,
    - Lee

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Oct 02, 2015 @ 15:38
    Lee Kelleher
    1

    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);
    
  • Mark 255 posts 612 karma points
    Oct 02, 2015 @ 17:14
    Mark
    1

    Thanks @Lee

    I'll do some testing early next week, and update you (and hopefully mark the solution) once I'm done.

    Thanks, Mark

  • Mark 255 posts 612 karma points
    Oct 07, 2015 @ 11:05
    Mark
    0

    Hi @Lee

    Unfortunately I've run straight into an issue where UmbracoContext.Current is null.

    Accessing some properties on document types threw:

    System.NullReferenceException: Object reference not set to an instance of an object.
    

    When I used the form:

    IPublishedContent.GetPropertyValue<string>("alias").Value
    

    or

    IPublishedContent.GetProperty("alias").Value
    

    Although, this seemed to work:

    IPublishedContent.GetProperty("alias").DataValue
    

    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.

  • Mark 255 posts 612 karma points
    Oct 07, 2015 @ 11:18
    Mark
    0

    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.

  • Mark 255 posts 612 karma points
    Oct 07, 2015 @ 13:52
    Mark
    1

    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);
                    }
    
Please Sign in or register to post replies

Write your reply to:

Draft