fixes n+1 query when assigning user types to users in user repo
This commit is contained in:
@@ -370,21 +370,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
private IEnumerable<IUser> ConvertFromDtos(IEnumerable<UserDto> dtos)
|
||||
{
|
||||
var foundUserTypes = new Dictionary<short, IUserType>();
|
||||
var userTypeIds = dtos.Select(x => Convert.ToInt32(x.Type)).ToArray();
|
||||
var allUserTypes = _userTypeRepository.GetAll(userTypeIds);
|
||||
|
||||
return dtos.Select(dto =>
|
||||
{
|
||||
//first we need to get the user type
|
||||
IUserType userType;
|
||||
if (foundUserTypes.ContainsKey(dto.Type))
|
||||
{
|
||||
userType = foundUserTypes[dto.Type];
|
||||
}
|
||||
else
|
||||
{
|
||||
userType = _userTypeRepository.Get(dto.Type);
|
||||
//put it in the local cache
|
||||
foundUserTypes.Add(dto.Type, userType);
|
||||
}
|
||||
{
|
||||
var userType = allUserTypes.Single(x => x.Id == dto.Type);
|
||||
|
||||
var userFactory = new UserFactory(userType);
|
||||
return userFactory.BuildEntity(dto);
|
||||
|
||||
Reference in New Issue
Block a user