2

Need help with the performance issue with sitecore GetUsers Function.

I have 80K sitecore users, and have custom property called "Accounts Assigned" in user profile. I am using pipe delimited in the "Accounts Assigned" property. example: 25909|25920|25670|25089

we are using this query to report the users assigned to particular Account.

Sitecore.Security.Accounts.UserManager.GetUsers().Where(x => x.Profile.GetCustomProperty("Accounts Assigned").Contains("25909"));

This is taking 140 seconds, is there a way to remediate that function,

2
  • How often do account assignments change, is adding caching an option?
    – Jeroen
    Feb 15, 2021 at 15:44
  • users can request change to their profile from website, so to answer your question assignments can change very frequently.
    – Shrad
    Feb 15, 2021 at 16:00

3 Answers 3

1

Sitecore user management is based ASP.Net Membership. ()

The architecture of ASP.Net membership wasn't designed to perform operations that you try to do quickly. How your code will work internally:

  1. It will get all users (80K)
  2. It will deserialize all profiles (Profiles are saved in a separate table. They are saved in the serialized way for flexibility to add any properties without changing database structure. It causes a trade-off: you can't add database index and quickly query profiles directly from database) (80K)
  3. It will get profile property "Accounts Assigned" for each user (80K)
  4. It will run .Net search inside string on required value. (80K)

I suggest you rethink your architecture and save values that you need to query in another place. It could be:

  • Cache
  • Index
  • Database (with a proper scheme for quick access)

P.S. I assume that you don't use Sitecore Identity Server as it wasn't mentioned in the question.

7
  • Thanks Anton. it is Sitecore commerce website. so I think Sitecore uses Identity server. but I am not sure how that information is stored in Identity server and retrieve that information from there. please let me know if there is a way to retrieve information from identity server. Just for your information: I can see all the users from the aspnet_Membership, aspnet_Profile, aspnet_UsersInRoles, & aspnet_Users tables in sitecore core database.
    – Shrad
    Feb 15, 2021 at 16:43
  • Anton, here is what I have in user profile caching. Step 1 Value: UserProfileCache 15 18.3 KB 18.3 KB 5 MB Step 2 Value: <setting name="Caching.UserProfileCacheSize" value="5MB"/>
    – Shrad
    Feb 15, 2021 at 17:12
  • That is very strange: It cached only 15 user profiles and took 18KB total. I expect that there should be 80K records, one per user.
    – Anton
    Feb 15, 2021 at 17:16
  • As it takes about 1 KB for 1 user profile, you will need 8000KB = 8MB for caching. (otherwise, the cache would not work properly, it will be rewritten all the time)
    – Anton
    Feb 15, 2021 at 17:18
  • I suggest you update Caching.UserProfileCacheSize setting and set it to at least 20MB to have some margin of safety.
    – Anton
    Feb 15, 2021 at 17:20
0

Instead can use Domain.GetDomain("domainName").GetUsers() which is much faster than UserManager.GetUsers().

For reference, please have a look at below attached url

https://sitecorecontextitem.wordpress.com/2014/07/28/get-all-sitecore-users-by-domain/

1
  • Thanks gupta, I am having a performance issue on applying the filter on the custom property, not on getting all the sitecore users. here is my filter linq query: XXXXXXXXXXXXXXXXXX.Where(x => x.Profile.GetCustomProperty("Accounts Assigned").Contains("25909"));
    – Shrad
    Feb 18, 2021 at 0:40
0

You could implement your own Caching (either sitecore custom cache if you want to see it also on the /sitecore/admin/cache.aspx page or application cache) for the list of users returned by your query, this way you would only run the query once. Then when users are requesting changes to their profile in the website you also add/remove them from the cache created previously.

Where are you using the result of the user query? Are you calling this query in author environment only or also on the public website?

Depending on how and where you are using the list of users and if powershell is installed in your Prod environment you can run a script in your code as described in the post https://blog.najmanowicz.com/2012/04/06/using-powershell-console-for-sitecore-in-your-own-code/. The script would be similar to the one you asked in Sitecore Powershell script to filter the users based on custom roles.

1
  • Thank you Cristi, I am using on public website, where company admin(role) of that account can manage the users of his company account.
    – Shrad
    Feb 22, 2021 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.