removed lazy loading of users
This commit is contained in:
parent
72a956d022
commit
e6359469b6
|
@ -28,18 +28,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
|||
/// </summary>
|
||||
public async void Run()
|
||||
{
|
||||
#if __MonoCS__
|
||||
try
|
||||
{
|
||||
await _userManager.RefreshUsersMetadata(CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
System.Console.WriteLine("RefreshUsersMetadata task error: No users? First time running?");
|
||||
}
|
||||
#else
|
||||
await _userManager.RefreshUsersMetadata(CancellationToken.None).ConfigureAwait(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -21,40 +21,11 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// </summary>
|
||||
public class UserManager : IUserManager
|
||||
{
|
||||
/// <summary>
|
||||
/// The _users
|
||||
/// </summary>
|
||||
private IEnumerable<User> _users;
|
||||
/// <summary>
|
||||
/// The _user lock
|
||||
/// </summary>
|
||||
private object _usersSyncLock = new object();
|
||||
/// <summary>
|
||||
/// The _users initialized
|
||||
/// </summary>
|
||||
private bool _usersInitialized;
|
||||
/// <summary>
|
||||
/// Gets the users.
|
||||
/// </summary>
|
||||
/// <value>The users.</value>
|
||||
public IEnumerable<User> Users
|
||||
{
|
||||
get
|
||||
{
|
||||
// Call ToList to exhaust the stream because we'll be iterating over this multiple times
|
||||
LazyInitializer.EnsureInitialized(ref _users, ref _usersInitialized, ref _usersSyncLock, LoadUsers);
|
||||
return _users;
|
||||
}
|
||||
internal set
|
||||
{
|
||||
_users = value;
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
_usersInitialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
public IEnumerable<User> Users { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The _logger
|
||||
|
@ -78,11 +49,13 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="configurationManager">The configuration manager.</param>
|
||||
/// <param name="userRepository">The user repository.</param>
|
||||
public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
UserRepository = userRepository;
|
||||
ConfigurationManager = configurationManager;
|
||||
Users = new List<User>();
|
||||
}
|
||||
|
||||
#region UserUpdated Event
|
||||
|
@ -132,6 +105,11 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
return Users.FirstOrDefault(u => u.Id == id);
|
||||
}
|
||||
|
||||
public async Task Initialize()
|
||||
{
|
||||
Users = await LoadUsers().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Authenticates a User and returns a result indicating whether or not it succeeded
|
||||
/// </summary>
|
||||
|
@ -185,7 +163,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// Loads the users from the repository
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{User}.</returns>
|
||||
private IEnumerable<User> LoadUsers()
|
||||
private async Task<IEnumerable<User>> LoadUsers()
|
||||
{
|
||||
var users = UserRepository.RetrieveAllUsers().ToList();
|
||||
|
||||
|
@ -198,10 +176,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
|
||||
user.DateLastSaved = DateTime.UtcNow;
|
||||
|
||||
var task = UserRepository.SaveUser(user, CancellationToken.None);
|
||||
|
||||
// Hate having to block threads
|
||||
Task.WaitAll(task);
|
||||
await UserRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
users.Add(user);
|
||||
}
|
||||
|
@ -284,7 +259,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
}
|
||||
|
||||
public event EventHandler<GenericEventArgs<User>> UserCreated;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates the user.
|
||||
/// </summary>
|
||||
|
@ -311,11 +286,11 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
Users = list;
|
||||
|
||||
user.DateLastSaved = DateTime.UtcNow;
|
||||
|
||||
|
||||
await UserRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
EventHelper.QueueEventIfNotNull(UserCreated, this, new GenericEventArgs<User> { Argument = user }, _logger);
|
||||
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
|
|
@ -292,6 +292,8 @@ namespace MediaBrowser.ServerApplication
|
|||
await Task.WhenAll(itemsTask, displayPreferencesTask, userdataTask).ConfigureAwait(false);
|
||||
progress.Report(100);
|
||||
|
||||
await ((UserManager) UserManager).Initialize().ConfigureAwait(false);
|
||||
|
||||
SetKernelProperties();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user