mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-08-01 20:49:12 +08:00
Optimizing user roles lazy loading
This commit is contained in:
parent
2bdc29d8e9
commit
15e4e27c46
@ -13,11 +13,9 @@ namespace Orchard.Roles.Handlers {
|
||||
_userRolesRepository = userRolesRepository;
|
||||
|
||||
Filters.Add(new ActivatingFilter<UserRolesPart>("User"));
|
||||
OnLoaded<UserRolesPart>((context, userRoles) => {
|
||||
userRoles.Roles = _userRolesRepository
|
||||
.Fetch(x => x.UserId == context.ContentItem.Id)
|
||||
.Select(x => x.Role.Name).ToList();
|
||||
});
|
||||
OnInitialized<UserRolesPart>((context, userRoles) => userRoles._roles.Loader(value => _userRolesRepository
|
||||
.Fetch(x => x.UserId == context.ContentItem.Id)
|
||||
.Select(x => x.Role.Name).ToList()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Utilities;
|
||||
|
||||
namespace Orchard.Roles.Models {
|
||||
public class UserRolesPart : ContentPart, IUserRoles {
|
||||
public UserRolesPart() {
|
||||
Roles = new List<string>();
|
||||
}
|
||||
|
||||
public IList<string> Roles { get; set; }
|
||||
internal LazyField<IList<string>> _roles = new LazyField<IList<string>>();
|
||||
|
||||
public IList<string> Roles {
|
||||
get { return _roles.Value; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user