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.
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.
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.
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.
Traversing media folder - too slow
here's a simple code to get the media children (and grandchildren) of a specified media folder.
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 ?
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
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
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
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
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.
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
is working on a reply...