Copied to clipboard

Flag this post as spam?

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


  • Søren Reinke 158 posts 206 karma points c-trib
    Dec 02, 2009 @ 15:14
    Søren Reinke
    0

    .GetProperty on a member object slow

    Hi there

    I have the following code:

           public IntranetMember(umbraco.cms.businesslogic.member.Member member)
            {
                Firstname = member.getProperty("firstName").Value.ToString();
                Lastname = member.getProperty("lastName").Value.ToString();

    remove 10 more 'get property' lines.

    When i debug the code, the first member.getProperty is very slow, takes about 3-5 seconds to run, after that the rest goes very fast.

    I call this constructor once for each member object i got from umbraco, it is only for the first object it takes a long time.

     

    Does anyone have a clue about why this is the case ?

    The code is used to search employees in my company, and it is pretty annoying that a simple search takes 5 seconds, there is only 150 objects.

     

    Best regards

    Søren Reinke

  • Tim 225 posts 690 karma points
    Dec 03, 2009 @ 15:57
    Tim
    0

    Hi,

    As far as I'm aware (core team feel free to correct me!) the getProperty() method does a db lookup for each property.

    This means that for each member you are doing 12 or so db queries.

    Not sure if there is a way round this. However if your first query is taking 2-3 seconds than subsequent queries are very quick it sounds to me like the DB might be spooling up on the first query then is available and quick for the next queries.

    If you are using SQL2005 ensure your DB has AutoClose set to false. (It's in the options for the DB)

    T

  • Chris Koiak 700 posts 2626 karma points
    Dec 03, 2009 @ 16:03
    Chris Koiak
    0

    There is an interesting approach using XML you could use http://our.umbraco.org/forum/developers/xslt/1812-getting-members-groups-from-member-id-in-xslt

    Any access to the database can be particularly slow, I'd recommend adding some caching to the sample in the link and using that.

  • Tim 225 posts 690 karma points
    Dec 03, 2009 @ 16:34
    Tim
    0

    Hi Chris,

    That's certainly an interesting approach, although it could get unwieldy in itself if there are lots of members with lots of properties as you'd be shunting big lumps of data about. 

    Perhaps it would better to write a Lucene indexer which indexed members and properties in the DB??

    Not sure if this has ever been done.

    T

  • Chris Koiak 700 posts 2626 karma points
    Dec 03, 2009 @ 17:13
    Chris Koiak
    0

    A lucene index would be a great idea. I don't think anything like this exists at the moment.

  • Tim 225 posts 690 karma points
    Dec 03, 2009 @ 19:10
    Tim
    0

    I'll add it to my list of things to do ;-)

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Dec 03, 2009 @ 22:36
    Aaron Powell
    0

    Tim is correct, getProperty does a DB look up each time that you call it. Without some big API design changes this can't be fixed (and isn't on the cards for 4.1).

    I'm not sure that a lucene index would be a good idea though, it's that a little big insecure, storing the personal details like that? But you may be able to achieve it with Umbraco Examine, I'll check with Shannon.

  • Søren Reinke 158 posts 206 karma points c-trib
    Dec 04, 2009 @ 10:42
    Søren Reinke
    0

    Hi there

    Thanks a lot for the answers.

    The solution I have used, is a simple caching of the 150 members including their properties.

Please Sign in or register to post replies

Write your reply to:

Draft