Obsolete hell, does IDocumentUrlService.GetDocumentKeyByRoute() make use of IPublishedContent or IContent for lookup?

I’m building a custom ContentFinder where I want to retrieve an IPublishedContent page based on the request path. In v13 (LTS), it was possible to do this without warnings using the following on IUmbracoContext:


var currentContent = umbracoContext.Content.GetByRoute(path, culture: culture);

However, in v16, this approach is no longer recommended, and you’re advised to use IPublishedContentCache.GetByRoute() instead. That seemed fine, so I switched to that method — but then I noticed that it’s now marked [Obsolete] without any clear explanation.

I then considered using IDocumentUrlService.GetDocumentKeyByRoute() to retrieve the node’s key, so that I could later fetch the content via IPublishedContentCache.GetByIdAsync().

Sounds good, right? That’s what I thought — until I realized that IDocumentUrlService.GetDocumentKeyByRoute() might internally use IContentService. That would mean it’s querying the database directly, not the cache, which is something I want to avoid in a ContentFinder, since that would immediately impact performance for every request.

So my question is:

Does IDocumentUrlService.GetDocumentKeyByRoute() use IPublishedContent (cached) or IContent (database) internally for its lookup?

If it uses IContent, that would not be acceptable for my use case, and I’d be interested in any alternatives that avoid database access and rely solely on the cache.

Regards,
Joppe

Hey Joppe,

Not at the computer but I think you need to use IDocumentNavigationQueryService

Hope this helps
Matt

I’d probably copy what Umbraco does in core and assume that they have optimized it for performance:
Umbraco-CMS/src/Umbraco.Core/Routing/ContentFinderByUrlNew.cs at main · umbraco/Umbraco-CMS

I think I’ll stick with this approach indeed. Thanks for providing the source code — it confirmed what I suspected:

var documentKey = _documentUrlService.GetDocumentKeyByRoute(
    docreq.Domain is null ? route : route.Substring(docreq.Domain.ContentId.ToString().Length),
    docreq.Culture,
    docreq.Domain?.ContentId,
    umbracoContext.InPreviewMode
);

Thanks again!
Joppe

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.