Copied to clipboard

Flag this post as spam?

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


  • Hrvoje Hudoletnjak 5 posts 95 karma points
    Dec 21, 2023 @ 12:18
    Hrvoje Hudoletnjak
    0

    Finding content item by name

    I was using helper.ContentSingleAtXPath("//pageName") but thats depreched now and will be removed.

    Whats the best and most optimal way of getting a (deep) content by its name?

    Doing helper.ContentAtRoot().First().Children.Where(x => x.Name == "Foo") seems very unoptimal and SELECT N+1 issue, and it doesn't work if its a deep nested page.

  • Stefan Stankovic 12 posts 119 karma points
    Dec 21, 2023 @ 13:45
    Stefan Stankovic
    0

    Have you tried to use the examine search? https://docs.umbraco.com/umbraco-cms/reference/searching/examine/quick-start If you need published content, you can find content by node name and then use IUmbracoContextAccessor (_context is IUmbracoContextAccessor)

               var cache = _context.GetRequiredUmbracoContext();
    
                if (cache == null || cache.Content == null)
                {
                    continue;
                }
    
                var publishedContent = cache.Content.GetById(id);
    
  • Hrvoje Hudoletnjak 5 posts 95 karma points
    Dec 21, 2023 @ 14:08
    Hrvoje Hudoletnjak
    0

    I didn't consider search, probably because I don't exactly know how it works in Umbraco. Search is usually full-text search, and eventually consistent, so doesn't make sense to use full text search to find one item with particular property value, and when you need most recent value. I would expect Umbraco has API for that kind of "exact" querying.
    Also, can't cache be stale or empty, even the content is there? I would expect filtering/querying API to use cache behind the scene, and just go to the Db if cache is empty. But as i said, I don't know how Umbraco is designed for these kind of things.

Please Sign in or register to post replies

Write your reply to:

Draft