mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05:00 
			
		
		
		
	removed lazy loading of users
This commit is contained in:
		
							parent
							
								
									72a956d022
								
							
						
					
					
						commit
						e6359469b6
					
				@ -27,20 +27,9 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
 | 
			
		||||
        /// Runs this instance.
 | 
			
		||||
        /// </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>
 | 
			
		||||
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@ -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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user