How to purge non existent and inactive users

 Hello all,

Here is the thing. Over time a user may leave a company or worse, was uploaded but never came. Yeah, I know. Bad practice. The result is that you have users in the system that

  1. Never been active 
  2. Have been active in the past, but from your mailserver you know this email bounces, so this user will never respond again.

How have you dealt with purging your user base?



This thread was automatically locked due to age.
[unlocked by: Kevin Cunningham at 2:25 AM (GMT -5) on Fri, Sep 1 2017]
Parents
  • Can you explain the "moreRecords" variable and how that becomes true/false?  because you set "pageSize" to 100 and never change it.
     
    do
        {
            var users = PublicApi.Users.List(new UsersListOptions() {PageSize = pageSize, PageIndex = pageIndex});
            moreRecords = users.TotalCount == pageSize;
     
            foreach (var user in users)
            {
                if (user.LastLoginDate < DateTime.Now.AddYears(-5) && user.TotalPosts == 0)
                {
                    PublicApi.Users.Delete(new UsersDeleteOptions
                    {
                        Id = user.Id,
                        ReassignedUsername = PublicApi.Users.AnonymousUserName
                    });
                }
            }
     
            pageIndex++;
        } while (moreRecords);
  • The page size never changes, but the pageIndex is incremented each call. The idea is, if we have as many records as the page size, then there are more records after the current pageIndex, so we continue. Once we have fewer records in the current page than the pageSize, we know we're on the last page. There is a bug though. It should read:

    moreRecords = users.Count == pageSize;
Reply Children