Working with lac users in Sitecore

Challenge:

Recently we were working on a Project which includes lac of users. Our application includes Login/Logout Mechanism – which is the base for any Ecommerce Application. Yes it is an Ecommerce Application.

 

Initially while developing a Project we were having few records around 2000. So Sitecore was performing pretty well. But as we went Live with 300000 records. Sitecore went down. It took roughly 4+ Minutes to GetAllUsers. And 5 Minutes to process all the records, compare Custom Property which was needed in our case. So it was taking around 10 Minutes to Login. It was very critical time for us to get the things done as soon as possible. With the help of Sitecore – We came to know that only best approach in this case is to go with SQL Query. And Yes – Stored Procedure did our Job. We created a Stored Procedure that does the processing which we were doing via Code. So that reduced time to less than 6 Seconds – Hurray! (Refer: https://sitecorebasics.wordpress.com/2015/11/21/sitecore-login-time-from-10-minutes-to-seconds/ for more details on this.)
Sitecore internally uses the Membership Object of Asp.Net.

Initially we were using below approach:
Sitecore.Security.Accounts.UserManager.GetUsers() [It takes lot of time if there are more than 2 lac users. User won’t wait if takes more than few Seconds to Login]

We were required to include Active Directory users in Sitecore. So now our solution was also having Active Directory Users. We felt the little slowness in Login. So we changed the above approach and followed:

Domain.GetDomain(DomainName).GetUsers()
Till this point of time our solution was having 4k+ Users
including Active Directory Users.

We were also doing Scheduling process which takes all the users and performs few operations
based on the Custom Property of each User. We were trying the best approach.
Here fetching time was not a major concern but though we were looking for the best
solution as 10 minutes wait time is not at all acceptable.

Solution:

try
{
 MembershipUserCollection allUsers = Membership.GetAllUsers();

 foreach (MembershipUser user in allUsers)
 {
  var userObj = Sitecore.Security.Accounts.User.FromName(user.UserName, false);

  if ((userObj != null) && (userObj.Profile.GetCustomProperty("Site") == "/Site"))  
  {
                  // Do Processing
                }
         }
}
catch(Exception ex)
{
 // Log
}
With help of this approach – Time reduced to 10 Seconds from 5 Minutes. (Wow)
Please let me know if you have any other better approach and share if this helped you. Thanks!
Happy Sitecoring! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.