https://discord.umbraco.com logo
I am currently working on a project that
# umbraco-chat
s
I am currently working on a project that uses
UmbracoHelper
extensively. I remember it being considered a big no-no in older versions of Umbraco because of its impact on performance. Is this still the case in versions 13 and above?
r
so seeing the thread that @skttl got me pushed to show this I've been working round that with a couple of new format things
Copy code
public IEnumerable<IPublishedContent> GetPagesOfType(string contentType)
  {
      var contentCache = _contextFactory.EnsureUmbracoContext().UmbracoContext.Content;
      var nodes = new List<IPublishedContent>();


      if (contentCache != null)
      {

          var publishedContent = GetHomePage();

          //get this to work and we are good
          if (_navigationQueryService != null)
          {
              _navigationQueryService.TryGetDescendantsKeysOfType(publishedContent.Key, contentType, out IEnumerable<Guid> initialDescendantsKeysOfType);

              List<Guid> initialDescendantsOfTypeList = initialDescendantsKeysOfType.ToList();
              if (initialDescendantsOfTypeList != null)
              {
                  foreach (var itemKey in initialDescendantsOfTypeList)
                  {
                      var pubContent = contentCache.GetById(itemKey);
                      if (pubContent != null)
                      {
                          nodes.Add(pubContent);
                      }

                  }
              }
          }
      }

      if (nodes != null && nodes.Any())
      {
          return nodes;
      }

      return Enumerable.Empty<IPublishedContent>();

  }
and I've done variations on a theme get sitesetting page.. I'm sure I have a version where it works in multisite here you pass and i id , and i make sure its with relative content path etc
eg
Copy code
public  IPublishedContent? GetHomePage()
   {
       var contentCache = _contextFactory.EnsureUmbracoContext().UmbracoContext.Content;
       IPublishedContent? publishedContent = null;

       if (_navigationQueryService.TryGetRootKeysOfType(HomePage.ModelTypeAlias, out var rootKeys))
       {
           publishedContent = contentCache.GetById(rootKeys.FirstOrDefault());
       }

       return publishedContent;
   }
s
I have something similar, mine is just generic, so I can
Get<ContentModels.Whatever>()
, and then its cached per request 🙂
m
Aligned with this... has anyone done any recent testing to compare IPublishedContentQuery vs examine for getting at singular nodes by custom property && nodeTypeAlias? use-case is find me the folder (nodeTypeAlias) in the media section that has the developmentCode (customProperty) of XXXX, (create it if not existing during a contentSaving notification, so we have a place to store related assets for the editor)
r
@skttl I do have a couple of generic ones this was the first one I could find of that type where I used the new iipublished query style and as you said it’s then cached by request