Copied to clipboard

Flag this post as spam?

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


  • Ran Chen 40 posts 117 karma points
    Jun 13, 2017 @ 09:19
    Ran Chen
    0

    Traversing media folder - too slow

    here's a simple code to get the media children (and grandchildren) of a specified media folder.

    IPublishedContent docs = Umbraco.Media(xxx); // xxx = Media folder Id
    
    List<IPublishedContent> children = docs.Descendants(1).ToList(); 
    

    This folder contains ±1700 files. The time it takes it to run is more than 20 seconds (!)

    I need to go over all files to search for specific ones, but I guess it will not work where getting the list of files takes forever.

    Am I doing something wrong here ?

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Jun 13, 2017 @ 09:59
    Damiaan
    1

    This is by design I am afraid.

    Descendants will loop indeed over all folders and subfolders. It's normal to take some time.

    The real question is, what do you need to do? I don't think you want to show 1700 images on your website. The best practice is to load only the images you really need.

    If you need to search, you could use the examine index to search for images you need.

    Also, use Umbraco.TypedMedia(xxx) to retrieve strongly typed models intead of Dynamics.

    Kind regards
    Damiaan

  • Ran Chen 40 posts 117 karma points
    Jun 13, 2017 @ 10:17
    Ran Chen
    0

    Sorry guys, Forgot to mention - this is not an image search. All of these ±1700 files are documents (mostly pdf files).

    So, I guess you are right, adding a custom index would be the answer.

    Thanks

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jun 13, 2017 @ 10:01
    Ismail Mayat
    0

    will be quicker if you use the index and do an examine search. You will need to inject in a searchable path but it will be much faster than using UmbracoHelper.

    Regards

    Ismail

  • Alex Skrypnyk 6162 posts 24132 karma points MVP 8x admin c-trib
    Jun 13, 2017 @ 10:02
    Alex Skrypnyk
    0

    Hi

    I think it's possible to create custom Examine index with your images, like an index with id, name and url fields.

    And do search on this index - it will be 100 times faster.

    Thanks

    Alex

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Jun 13, 2017 @ 10:11
    Damiaan
    0

    I was soooooo quick to answer this one :-D

    The media is available in the default internal index. Like Alex said, creating a custom index would be possible too.

    What Ismail is referring too with the "searchable path" is a way to make the parent folder id available in the search index. Basically you create an extra index field on saving the Media. The value of this field should contain all parent id's separated with spaces instead of comma's. Like that you can retrieve images with a specified ancestor folder in your search query.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jun 13, 2017 @ 10:43
    Ismail Mayat
    0

    The external index also contains stub information of media (images /files) so you can search on this one as well however you will need searchable path.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft