Copied to clipboard

Flag this post as spam?

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


  • keilo 568 posts 1023 karma points
    Feb 13, 2017 @ 05:49
    keilo
    0

    Iterate all Members and Execute Save()

    I came across this weird issue, running on 7.5.9 assembly: 1.0.6247.17495

    when trying to rebuild the Member Index under Dev->Examine and click Optimize, it says it takes too long to execute and check logs.

    Logs shows something like

    "ERROR UmbracoExamine.DataServices.UmbracoLogService - Provider=InternalMemberIndexer, NodeId=-1
    System.Exception: Error indexing queue items,System.FormatException: 17/11/2016 09:17:40 is not a valid value for DateTime. ---> System.FormatException: String was not recognized as a valid DateTime."
    

    I cant seem to locate the which record field as i have 55K records.

    For this reason I cant seem to locate the member in Member Picker dialog.

    However, if I go to the Member individually and click on Save, then use Member Picker to search it shows this Member record.

    So I would like to iterate all members and for each execute Save() command via the API.

    What would be the ideal routine for something like that?

    ..Member.GetAll()..
    foreach {
            var memberService = Services.MemberService;
            var customMember = memberService.GetByEmail(foreachvariable.Email);
            memberService.Save(customMember);
    }
    
  • keilo 568 posts 1023 karma points
    Feb 13, 2017 @ 08:43
    keilo
    0

    I have tried using the following but it times out on the GetAll() call

     var Members = ApplicationContext.Current.Services.MemberService.GetAll(0, int.MaxValue, out totalRecords);
    
        foreach (var member in Members)
        {
            var memberService = ApplicationContext.Current.Services.MemberService;
            var customMember = memberService.GetByEmail(member.Email);
            memberService.Save(customMember);   
    
        }
    
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Feb 13, 2017 @ 12:25
    Dan Diplo
    1

    If it's timing out you should consider doing this in smaller batches. The first two parameters to GetAll are pageIndex and pageSize.

    So reduce the pageSize to a smaller value (say 500 records) and then, in a loop, increment the pageIndex accordingly until you've iterated all records.

    I believe these parameters are the same as the underlying provider uses, so see https://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.getallusers.aspx

  • keilo 568 posts 1023 karma points
    Feb 13, 2017 @ 13:13
    keilo
    0

    Thanks Diplo for the pointers and the link, much appreciated.

    I'll give that a try.

    cheers!

  • keilo 568 posts 1023 karma points
    Feb 14, 2017 @ 06:00
    keilo
    0

    Hi Diplo

    Do you know if there is any way to filter specific type of Member Types for GetAll;

    For instance if I wish to iterate all members of Type "Student", what would be the most efficient method?

        var students = ApplicationContext.Current.Services.MemberService.GetAll(start, page, out totalRecords);
    
        foreach (var member in Members-Of-Type-Student)
        {
                 ...
             }
    
Please Sign in or register to post replies

Write your reply to:

Draft