Copied to clipboard

Flag this post as spam?

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


  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Jan 19, 2012 @ 17:58
    Lee Kelleher
    0

    Get Latest Uploaded Media?

    Wondering what the best way of getting a list of the latest/uploaded media items.

    Any suggestions?

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Jan 19, 2012 @ 18:14
    Morten Bock
    1

    I think i'd go for a sql statement directly to the DB.

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Jan 19, 2012 @ 18:15
    Lee Kelleher
    0

    Current ideas...

    * Get root media node (-1) and all child nodes (in XML) and sort by createDate?

    * Query the database directly - to get the media node Ids?

    * Using Examine/Lucene? (not sure of the query)

    * uComponents/uQuery ... GetMediaByXPath ... but that's the same as querying all nodes right? (not sure)

    ... hmmm, this started out as an easy though... still open to suggestions.

    Cheers, Lee.

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Jan 19, 2012 @ 18:26
    Morten Bock
    0

    I think that any such query through the media api will suck the life right out of the site, of course depending on the amount of data involved, and the amount of caching you would be able to accept.

    Examine is a good thought, although I think it would be qiute a lot of code to create an index with the data you need, compared with the actual performance gain over a sql query.

    Another option would be to store the list of latest uploads in file/table/dictionary, and just update the list every time a file is uploaded using the events on media nodes.

  • Mads Krohn 211 posts 501 karma points c-trib
    Jan 19, 2012 @ 21:53
    Mads Krohn
    1

    Hey Lee

    So, in my opinion Examine is the way to go. Here is some sample code and a few points as to why I think that:

    Some time ago Shannon did a blogpost about using Examine to get fast media performance in Umbraco. I been using the code he provided a lot since, it just works and it is very performant. The link is here.

    Now, the smart thing about this is that Examine comes with two predefined indexes that Umbraco uses for searching internally. It just so happens that one of these indexes contains both the content and the media sections. So, to get started, you don't have to mess around with creating indexes, they are already there for you.

    Now, to some code:

    var criteria = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"].CreateSearchCriteria(UmbracoExamine.IndexTypes.Media);
    var filter = criteria.NodeTypeAlias("Image").Or().NodeTypeAlias("File").Or().NodeTypeAlias("Folder").Compile();
    var results = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"].Search(filter);

    Now, what happens here is that vi create a search criteria using the already defined index called InternalSearcher. When creating the criteria we tell Examine to only look for media when we later execute the search.

    We then set some more criterias, it really should be self-explanatory, compile it and then use the same search provider to search given our filter.
    And there you have it, a collection of every single media item, that is of course unless you added your own media types, but then you can just add them as criterias.

    Later on you can begin to build your own indexes. Examine provides ways to declare indexes that only search through published content or non-protected content and so on. There are a lot of possibilities.

    Now, Examine/Lucene is really damn fast, I strongly encourage you to go and try it. And if you are running Umbraco on .net 4.0, be sure to grap Examine version 1.4, indexing perfomance has been improved A LOT and indexing should be nearly instant. In my own projects I have created a MediaItem to wrap the search results, let me know if I can help out with more explanations and/or code.

    Just my 2 cents.

    Kind regards,
    Mads 

     

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Jan 20, 2012 @ 00:41
    Jeroen Breuer
    1

    Examine is probably the fastest way. Myself would use XML because I have more experience with that. Here you can find a topic on how I would do it: http://our.umbraco.org/forum/developers/razor/27521-Get-All-Images-in-Media-Gallery.

    Jeroen

  • Mads Krohn 211 posts 501 karma points c-trib
    Jan 20, 2012 @ 00:50
    Mads Krohn
    0

    A whole nother thing is that Umbraco seems to not save an update date for media items, only the create date.
    I saw this post about it and I can confirm that the issue is still present in version 4.7.1 at least.
    In the linked post there is a small workaround though :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies