Skip to content

Commit

Permalink
Fix #4906: cache the roles array in the user info object.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Zhong authored and bdukes committed Nov 10, 2021
1 parent eed6166 commit 0703796
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions DNN Platform/Library/Entities/Users/UserInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class UserInfo : BaseEntityInfo, IPropertyAccess, IUserInfo
private readonly ConcurrentDictionary<int, UserSocial> _social = new ConcurrentDictionary<int, UserSocial>();
private string _administratorRoleName;
private UserMembership _membership;
private UserProfile _profile;
private UserProfile _profile;
private string[] _roles;

/// <summary>
/// Initializes a new instance of the <see cref="UserInfo"/> class.
Expand Down Expand Up @@ -271,19 +272,26 @@ public string[] Roles
{
get
{
var socialRoles = this.Social.Roles;
if (socialRoles.Count == 0)
if (this._roles == null)
{
return new string[0];
var socialRoles = this.Social.Roles;
if (socialRoles.Count == 0)
{
this._roles = 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)
.ToArray();
}
}

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 { }
Expand Down

0 comments on commit 0703796

Please sign in to comment.