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?
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.
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.
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:
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?
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.
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
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
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.
is working on a reply...