Copied to clipboard

Flag this post as spam?

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


  • Peter Rombouts 71 posts 265 karma points
    Mar 14, 2013 @ 09:56
    Peter Rombouts
    0

    Media Library - Random Item Performance

    Hi all,

    I've been having some performance issues with getting a random image from Media library.
    The goal is to get the latest 30 images, and take 5 random images for display purposes.

    The code is as following:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using System.Linq;
    @using DigibizAdvancedMediaPicker;
    
    @{ 
    var parent = @Model.MediaById(Parameter.RootNode);
        if (parent != null) {
            var items = parent.Descendants("Image").OrderBy("id desc").Take(30);
            for(var i = 0; i < Convert.ToInt32(Parameter.NumberOfItems); i++)
            {
                var item = items.Random();
                Render Something with my @item.Url
            }
            }
    }
    }
    

    The problem seems to be the 'parent.Descendants' part, because the Media Library is *huge*.
    Caching the control is not really a solution, but fixes it for now.

    Has anyone encountered this problem, and have found a solution for this?

  • Andreas Iseli 150 posts 427 karma points
    Mar 18, 2013 @ 09:32
    Andreas Iseli
    0

    I also had problems with content items when using the uncached method. I now always use the uQuery class accessing the contents. I'm not sure about the media part, but that should be cached as well. Give it a try. I'll have a closer look at it soon but for the moment I'm too busy.

  • Peter Rombouts 71 posts 265 karma points
    Mar 18, 2013 @ 10:53
    Peter Rombouts
    0

    Thanks alot, I'll try to take a look at the documentation and post a reply when I've fixed the problem (hopefully)

    Kind regards,
    Peter Rombouts

  • Peter Rombouts 71 posts 265 karma points
    May 27, 2013 @ 09:49
    Peter Rombouts
    0

    Solution to my problem was using Examine.

    This article explains how to implement it easily:

    http://shazwazza.com/post/Ultra-fast-media-performance-in-Umbraco

     

  • Andreas Iseli 150 posts 427 karma points
    May 27, 2013 @ 09:54
    Andreas Iseli
    0

    Hi Peter, thanks for your reply.

    I personally use the IMediaService now. It performes really well and is sufficient for my purposes. But when using even larger libraries than mine, there will be now way around Examine.

Please Sign in or register to post replies

Write your reply to:

Draft