I'm trying to fetch a user by its custom profile property. The code times out because there are more than 100000 records. So, I wrote a second method, which seems a little better, but maybe because the user was found in the first set itself.
- I would like to know if there is a better or faster way to get the result.
Also, is there a way to get
var pagewiseUsers
ordered by Descending order of created date, as it will improve the search time for this particular use case.public static User GetUserByProfileProperty(string domain, ID profileID, string profilePropertyName, string profilePropertyValue) { User user = null; Item profileItem = GetItemFromCoreDB(profileID); if (profileItem != null) { //METHOD 1 - which times out user = Domain.GetDomain(domain).GetUsers() .Where(x => x.Profile.GetCustomProperty(profilePropertyName) == profilePropertyValue).FirstOrDefault(); //METHOD 2 int totalUsersCount = Domain.GetDomain(domain).GetUserCount(); int pageSize = 10000; int totalPages = (totalUsersCount + pageSize - 1) / pageSize; for (int pageIndex = 0; pageIndex < totalPages; pageIndex++) { var pagewiseUsers = Domain.GetDomain(domain).GetUsers(pageIndex, pageSize); if (pagewiseUsers != null && pagewiseUsers.Count() > 0) { user = pagewiseUsers.Where(x => x.Profile.GetCustomProperty(profilePropertyName) == profilePropertyValue).FirstOrDefault(); if(user != null) break; } } } return user; }