From ae9ca40a30e8544256289b673f9bb46f760a3b44 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 21 Feb 2024 11:45:54 +0800 Subject: [PATCH] fix the user roles cache issue. --- .../Library/Entities/Users/UserInfo.cs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/DNN Platform/Library/Entities/Users/UserInfo.cs b/DNN Platform/Library/Entities/Users/UserInfo.cs index 53695cb868d..c214dc36722 100644 --- a/DNN Platform/Library/Entities/Users/UserInfo.cs +++ b/DNN Platform/Library/Entities/Users/UserInfo.cs @@ -33,10 +33,10 @@ namespace DotNetNuke.Entities.Users public class UserInfo : BaseEntityInfo, IPropertyAccess, IUserInfo { private readonly ConcurrentDictionary social = new ConcurrentDictionary(); + private readonly ConcurrentDictionary roles = new ConcurrentDictionary(); private string administratorRoleName; private UserMembership membership; private UserProfile profile; - private string[] roles; /// Initializes a new instance of the class. public UserInfo() @@ -206,26 +206,24 @@ public string[] Roles { get { - if (this.roles == null) + return this.roles.GetOrAdd(this.PortalID, i => { var socialRoles = this.Social.Roles; if (socialRoles.Count == 0) { - this.roles = new string[0]; + return new string[0]; } else { - this.roles = (from r in this.Social.Roles - where - r.Status == RoleStatus.Approved && - (r.EffectiveDate < DateTime.Now || Null.IsNull(r.EffectiveDate)) && - (r.ExpiryDate > DateTime.Now || Null.IsNull(r.ExpiryDate)) - select r.RoleName) + return (from r in this.Social.Roles + where + r.Status == RoleStatus.Approved && + (r.EffectiveDate < DateTime.Now || Null.IsNull(r.EffectiveDate)) && + (r.ExpiryDate > DateTime.Now || Null.IsNull(r.ExpiryDate)) + select r.RoleName) .ToArray(); } - } - - return this.roles; + }); } set