Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 24, 2011 @ 14:36
    Bo Damgaard Mortensen
    0

    Stored Procedure to get all members

    Hi all,

    I'm struggleing a bit with a stored procedure to fetch all members of Umbraco including their properties.

    What I'm doing now is:

    BEGIN
        SET NOCOUNT ON;
        DECLARE @memberId INT
        SELECT Member.nodeId AS mId, Member.Email AS Email, Property.Alias AS Alias, ISNULL(CONVERT(VARCHAR, PreValues.dataInt), PreValues.dataNvarchar) AS Data, PreValues.dataNtext
        FROM cmsMember Member
        INNER JOIN cmsPropertyData PreValues ON PreValues.contentNodeId = Member.nodeId
        INNER JOIN cmsPropertyType Property ON Property.id = PreValues.propertytypeid
        INNER JOIN cmsMember2MemberGroup mg ON mg.Member = Member.nodeId
        ORDER BY nodeID, Property.Alias
    
    END

    While this gives me the "right" amount of data it doubles the output because of the joins, so every email address is output for every property.alias there is.

    Has anyone figured out a better way to do this? :-) I'm aware that your should'nt be querying the database directly, but as we all know: the Member.GetAll() method is very slow when the memberbase is big.

    Any help and/or input on this is greatly appreciated!

    Thanks a lot in advance.

    - Bo

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Nov 24, 2011 @ 14:40
    Ismail Mayat
    1

    Bo,

    Which version of umbraco are you using? If >4.5 then use examine to pull back all members and data it will be lightening quick.

    Regards

    Ismail

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 24, 2011 @ 14:41
    Bo Damgaard Mortensen
    0

    Hi Ismail,

    Thanks a lot for your input!

    I am in fact on a 4.7.1 install. But isn't Examine only for searching a criteria? It is possible to pull *all* members just from a single call to Examine?

    Thanks again, much appreciated!

    - Bo

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Nov 24, 2011 @ 14:47
    Richard Soeteman
    0

    Do you need the data in your website, or do you need it to export the member data to csv. In case of the last option you might want to checkout Memberexport. http://our.umbraco.org/projects/website-utilities/memberexport It's lightning fast and free for up to 200 members, so you can try it.

    Cheers,

    Richard

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Nov 24, 2011 @ 14:48
    Ismail Mayat
    1

    Bo,

    Yes you can i am fairly you can  certain the field __IndexType will have member in it. Create an index and then look into it using luke http://www.getopt.org/luke/ your query would then be something like

    var criteria = searcher.CreateSearchCriteria(IndexTypes.Member);

    then further refine the query to pull back members based on certain type?  I dont have member index handy if you can paste fields in member index only need field names then i can help further refine the query for you.

    Regards

    Ismail

     

     

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 24, 2011 @ 14:48
    Bo Damgaard Mortensen
    0

    Hi Richard,

    No, "sadly" I have to display the data on the website. Great suggestion however! :)

    - Bo

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 24, 2011 @ 14:50
    Bo Damgaard Mortensen
    0

    @Ismail: thanks a lot! :-) I'll try to create the index then and see how it comes out.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Nov 24, 2011 @ 15:07
    Ismail Mayat
    1

    Bo,

    Ok i found an old index with members and in there you have field __NodeTypeAlias which is the type of member so then your query would be

    var criteria = searcher.CreateSearchCriteria(IndexTypes.Member);

    IBooleanOperation query = criteria.NodeTypeAlias("useralias");

    //if you have more than one type of member 

    query = query.Or().Field("__NodeTypeAlias","anotheralias")

    obviously replace useralias and anotheralias with your aliases

    Regards

    Ismail

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 24, 2011 @ 15:25
    Bo Damgaard Mortensen
    0

    Hi Ismail,

    Thanks again! :-)

    Haven't used Examine that much really, so I'm a bit insecure here.

    As far as I can see the .Search() method takes a criteria parameter, so what exactly is the query variable used for in your case? :-)

    Also, I'm getting a YSOD nullpointer exception on this line: 

    var criteria = ExamineManager.Instance.SearchProviderCollection["MemberSearcher"].CreateSearchCriteria(IndexTypes.Member);

    Doublechecked the name of my searchproviders name and it looks alright.

    - Bo

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Nov 24, 2011 @ 15:34
    Hendy Racher
    0

    Hi Bo,

    Here's another suggestion... all the members (and their data) are also stored in the cmsContentXml table which should make for a simpler query:

    DECLARE @nodeObjectType AS UNIQUEIDENTIFIER
    SET @nodeObjectType ='39EB0F98-B348-42A1-8662-E7EB18487560' -- MEMBER

    SELECT *
    FROM cmsContentXml
    WHERE nodeId IN (
    SELECT id
    FROM umbracoNode
    WHERE nodeObjectType = @nodeObjectType AND trashed = 0
    )

    The above will return a row for each member containing an XML fragment with all their member data.

    If you have uComponents installed, the following uQuery API call might also be useful, as it'll return an XML document containing all members - this should be fast, as it's one db hit to get the complete XML.

    XmlDocument xmlDocument = uQuery.GetPublishedXml(UmbracoObjectType.Member);

    HTH,

    Hendy

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Nov 24, 2011 @ 15:38
    Ismail Mayat
    0

    ok try the following

    BaseSearchProvider searcher = ExamineManager.Instance.SearchProviderCollection["MemberSearcher"];

     var criteria = searcher.CreateSearchCriteria(IndexTypes.Member);

    var results = searcher.Search(criteria);

    Regards

    Ismail

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 24, 2011 @ 15:52
    Bo Damgaard Mortensen
    1

    Jeeeeeeeeezzzzz!!

    This does just what I want: <xsl:for-each select="ucomponents.members:GetMembersByType('MyMemberType')">

    uComponents to the rescue! Seems to be really fast aswell :-)

    However, I'm certainly going to have a look at Examine anyway since I also have to make some advanced searching on the site (and on members..)

    So, thanks so much both Hendy and Ismail - you guys rock! Be sure to poke me at CG12 for a beer ;-)

    All the best,

    - Bo

  • Winston 4 posts 24 karma points
    Nov 29, 2012 @ 09:51
    Winston
    0

    How about this, i have just googled and found this forum, just got an idea how to query members along with properties, this is what iv'e got instead  of using INNER JOIN posted by bo mortensen ive just do tweak on the query =>

     

     

            DECLARE @memberId INT

            SELECT Member.nodeId AS mId, Member.Email, Property.Alias, ISNULL(CONVERT(VARCHAR, PreValues.dataInt), PreValues.dataNvarchar) AS Data, 

                   PreValues.dataNtext

    FROM  cmsMember AS Member LEFT OUTER JOIN

                   cmsPropertyData AS PreValues ON PreValues.contentNodeId = Member.nodeId LEFT OUTER JOIN

                   cmsMember2MemberGroup AS mg ON mg.Member = Member.nodeId LEFT OUTER JOIN

                   cmsPropertyType AS Property ON Property.id = PreValues.propertytypeid

    ORDER BY mId, Property.Alias

    ===========================

    AND IT LISTED AS FOLLOWS

    ===========================

    [email protected]

    [email protected]

    [email protected]

    [email protected]

    [email protected]

    [email protected]

    [email protected]

    [email protected]

  • Winston 4 posts 24 karma points
    Nov 29, 2012 @ 09:51
    Winston
    0

    How about this, i have just googled and found this forum, just got an idea how to query members along with properties, this is what iv'e got instead  of using INNER JOIN posted by bo mortensen ive just do tweak on the query =>

     

     

            DECLARE @memberId INT

            SELECT Member.nodeId AS mId, Member.Email, Property.Alias, ISNULL(CONVERT(VARCHAR, PreValues.dataInt), PreValues.dataNvarchar) AS Data, 

                   PreValues.dataNtext

    FROM  cmsMember AS Member LEFT OUTER JOIN

                   cmsPropertyData AS PreValues ON PreValues.contentNodeId = Member.nodeId LEFT OUTER JOIN

                   cmsMember2MemberGroup AS mg ON mg.Member = Member.nodeId LEFT OUTER JOIN

                   cmsPropertyType AS Property ON Property.id = PreValues.propertytypeid

    ORDER BY mId, Property.Alias

    ===========================

    AND IT LISTED AS FOLLOWS

    ===========================

    [email protected]

    [email protected]

    [email protected]

    [email protected]

    [email protected]

    [email protected]

    [email protected]

    [email protected]

Please Sign in or register to post replies

Write your reply to:

Draft