Copied to clipboard

Flag this post as spam?

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


  • Muhammad Umar 11 posts 121 karma points
    Aug 17, 2020 @ 15:37
    Muhammad Umar
    0

    Taking long time to get media url for 21 blogs on page

    I have a blogs page showing 21 blogs. The performance of this page is slow and loading at 40 seconds. I have done debugging using miniprofiler to see where it is taking time and i see that it is making multiple calls to db to get the blog image url and per image there is 4 sql queries it is executing. I am showing 21 blogs on one page so that 4 x 21.

    Is there a way of getting media url without hitting db.

    I am using below code to get media url

    Blog.GetPropertyValue<IPublishedContent>("blogFeaturedImage").Url;
    
  • Steve Morgan 1346 posts 4453 karma points c-trib
    Aug 17, 2020 @ 15:58
    Steve Morgan
    0

    How are you getting Blog?

    The line you have there should all come from the cache.

  • Muhammad Umar 11 posts 121 karma points
    Aug 17, 2020 @ 16:30
    Muhammad Umar
    0

    Method for getting blogs:

    public static IEnumerable<IPublishedContent> GetPagedBlogsLatestFirst(IPublishedContent rootNode, int numberOfItemsPerPage, int pageNo)
            {
                IEnumerable<IPublishedContent> Blogs = rootNode
                                                       .Descendants("blogItem")
                                                       .Where(x => x.IsVisible())
                                                       .OrderByDescending(x => x.HasProperty("publishDateOverride")
                                                                               && x.HasValue("publishDateOverride")
                                                                               ? x.GetPropertyValue<DateTime>("publishDateOverride")
                                                                               : x.CreateDate)
                                                       .Skip((pageNo - 1) * numberOfItemsPerPage)
                                                       .Take(numberOfItemsPerPage);
    
                return Blogs;
            }
    

    Blog is variable declared for foreach loop.

    foreach (var Blog in Blogs)  {
        string FeaturedImg = Blog.GetPropertyValue<IPublishedContent>("blogFeaturedImage").Url;}
    

    I was also expecting this to come from cache as well. Using Miniprofiler package shows it is hitting the db to get the media information and it runs 4 sql queries shown below each time it needs to retrieve the media url. A total of 84 sql queries are executed.Miniprofiler

    I can see the page loads a lot faster once i remove the line of code to get media url.

    First query:

        DECLARE @0 nvarchar(40) = N'9d1c3e10-b0d7-48ee-be71-a4b5cff034cb',
            @1 nvarchar(40) = N'b796f64c-1f99-4ffb-b886-4bf4bc011a9c',
            @2 nvarchar(40) = N'92849b1e-3904-4713-9356-f646f87c25f4';
    
    SELECT id FROM umbracoNode WHERE uniqueId=@0 AND (nodeObjectType=@1 OR nodeObjectType=@2)
    

    Second query:

    DECLARE @0 nvarchar(40) = N'b796f64c-1f99-4ffb-b886-4bf4bc011a9c',
            @1 int = 113677;
    
    SELECT TOP 1 *
    FROM [cmsContentVersion]
    INNER JOIN [cmsContent]
    ON [cmsContentVersion].[ContentId] = [cmsContent].[nodeId]
    INNER JOIN [umbracoNode]
    ON [cmsContent].[nodeId] = [umbracoNode].[id]
    WHERE (([umbracoNode].[nodeObjectType] = @0))
    AND (umbracoNode.id = @1)
    ORDER BY ([cmsContentVersion].[VersionDate]) DESC
    

    Third query:

        DECLARE @0 nvarchar(40) = N'b796f64c-1f99-4ffb-b886-4bf4bc011a9c',
            @1 int = 113677;
    
    SELECT a.id, a.value, a.sortorder, a.alias, a.datatypeNodeId
    FROM cmsDataTypePreValues a
    WHERE EXISTS(
        SELECT DISTINCT b.id as preValIdInner
        FROM cmsDataTypePreValues b
            INNER JOIN cmsPropertyType
            ON b.datatypeNodeId = cmsPropertyType.dataTypeId
        INNER JOIN 
                (SELECT cmsContent.contentType FROM [cmsContentVersion]
    INNER JOIN [cmsContent]
    ON [cmsContentVersion].[ContentId] = [cmsContent].[nodeId]
    INNER JOIN [umbracoNode]
    ON [cmsContent].[nodeId] = [umbracoNode].[id]
    WHERE (([umbracoNode].[nodeObjectType] = @0))
    AND (umbracoNode.id = @1)
    ) as docData
        ON cmsPropertyType.contentTypeId = docData.contentType
        WHERE a.id = b.id)   
    

    Fourth query:

    DECLARE @0 nvarchar(40) = N'b796f64c-1f99-4ffb-b886-4bf4bc011a9c',
            @1 int = 113677;
    
    SELECT cmsPropertyData.*
    FROM cmsPropertyData
    INNER JOIN cmsPropertyType
    ON cmsPropertyData.propertytypeid = cmsPropertyType.id
    INNER JOIN 
            (SELECT cmsContent.nodeId, cmsContentVersion.VersionId FROM [cmsContentVersion]
    INNER JOIN [cmsContent]
    ON [cmsContentVersion].[ContentId] = [cmsContent].[nodeId]
    INNER JOIN [umbracoNode]
    ON [cmsContent].[nodeId] = [umbracoNode].[id]
    WHERE (([umbracoNode].[nodeObjectType] = @0))
    AND (umbracoNode.id = @1)
    ) as docData
    ON cmsPropertyData.versionId = docData.VersionId AND cmsPropertyData.contentNodeId = docData.nodeId
    ORDER BY contentNodeId, versionId, propertytypeid
    
  • Steve Morgan 1346 posts 4453 karma points c-trib
    Aug 17, 2020 @ 16:55
    Steve Morgan
    0

    Hi,

    Seems very odd - do any of the other partials work differently or is this the only one you pass the root node in and use a static?

    What version of Umbraco are you on? Is it possibly a bug that's been patched?

    When you remove the call to the media url do you get any SQL queries?

    Try hardcoding the root node ID in that controller and rule things out one by one?

  • Muhammad Umar 11 posts 121 karma points
    Aug 17, 2020 @ 17:25
    Muhammad Umar
    0

    Other partials will be similar. I normally declare variable at top of Partial/View to get RootNode so i can use this throughout the partial so multiple calls are not made to get the root node. This method is only used on this one partial.

    Umbraco version 7.14.0

    Dont think there are any other Sql queries executed as Miniprofiler does not report any once i remove the call to get media url. You can see from screenshot below that the load time is massively reduced to 51ms for this partial just by removing this line of code. Before i discovered this i was under impression that it would be the LINQ query to get blogs that would be causing the loading times to be longer. I think since no Sql queries are reported those must be coming from cache as expected.

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft