Copied to clipboard

Flag this post as spam?

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


  • organic 108 posts 157 karma points
    May 27, 2015 @ 21:25
    organic
    1

    CustomLabel Examine example

    I wanted to share my /MacroPartial Custom Label code because I was able to greatly improve the performance of the admin by switching from calling the ContentService.GetById(key) for every option in the NuPicker, to using the Examine InternalIndexer instead.  I was rendering 500+ items per NuPicker.  Some doctypes had 2-3 NuPickers, and the real killer was putting a NuPicker in an Archetype datatype which let the admin users dynamically add as many as they wanted to the node!  10 pickers each loading 600+ options from the DB --> bad performance, even some locking of the web server.

    Bad way:

    IContent ic = ApplicationContext.Services.ContentService.GetById(Convert.ToInt32(Model.MacroParameters["key"]));

    Good way:
        var intSearchProvider = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"];
        var criteria = intSearchProvider.CreateSearchCriteria("content");
        var filter = criteria.Id(Convert.ToInt32(Model.MacroParameters["key"]));
        var results = intSearchProvider.Search(filter.Compile());
        if (results.Any())
        {
            var result = results.First();
            string alias = result.Fields["nodeTypeAlias"].ToUpper();
            string name = result.Fields["nodeName"];
            <span>@(alias + ": " + name)</span>
        }
  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    May 27, 2015 @ 23:32
    Hendy Racher
    0

    Thanks for sharing :) the ContentService hits the database, but how about using:

    IPublishedContent content = UmbracoHelper.TypedContent(Convert.ToInt32(Model.MacroParameters["key"]))

     

  • organic 108 posts 157 karma points
    May 28, 2015 @ 19:26
    organic
    0

    This NuPicker options needs to include unpublished content, which AFAIK, there is no cached API to query, hence the Examine technique.

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    May 28, 2015 @ 19:31
    Hendy Racher
    0

    Arrh, all makes sense now.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies