Copied to clipboard

Flag this post as spam?

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


  • Nikolas van Etten 202 posts 162 karma points
    Mar 12, 2011 @ 11:33
    Nikolas van Etten
    1

    Map media - performance considerations

    I need to import a great number of nodes using CMSImport and map media to each imported node. As there might be more than one media for each node, I cannot use the builtin media importer, but instead I'll create a FieldAdapter which takes care of the mapping.

    All media nodes are put in one folder which I know the id of. So basically I need to search for filenames in all child nodes of this already defined parent node. The filenames are saved as a text string array in the import.

    My question is how I should do this without killing the performance? With my limited .NET skills I would be tempted to do loop through all media child elements with something like:

                var media = new Media(1266);
                foreach (Media childMedia in media.Children)
                {
                    if (childMedia.getProperty("umbracoFile").Value == fileName))
                        return childMedia.Id;
                }
                return 0;

    This should work, but not for many nodes. So how can it be achieved in a better way? I assume LINQ or something would be better?! Or xpath?

     

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Mar 14, 2011 @ 09:25
    Richard Soeteman
    0

    Hi Nik,

    This would be a performance penalty on the first hit. Then the item is cached so for the second call it shouldn't be a problem.  What you also could do is use a sql query to return the node id like the one below. That will only use one query per fileName. Only thing is that you need to make sure your filenames are unique

    SELECT distinct ContentNodeId FROM cmsPropertyData where dataNVarchar like '%mediaFilename.ext'

    Hope this helps you,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft