From 804115bf8d526477756828ff4ca632c351e03b90 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 8 Apr 2013 11:55:53 -0400 Subject: [PATCH] remove and/or delay unnecessary startup work --- .../Playback/Progressive/VideoService.cs | 2 + .../BaseApplicationHost.cs | 11 -- .../Security/PluginSecurityManager.cs | 48 +++++-- MediaBrowser.Controller/Entities/BaseItem.cs | 6 +- MediaBrowser.Controller/Entities/Folder.cs | 6 +- .../Entities/Movies/Movie.cs | 2 +- MediaBrowser.Controller/Kernel.cs | 77 ---------- .../Library/ILibraryManager.cs | 39 ++++- .../MediaBrowser.Controller.csproj | 1 - .../MediaInfo/FFMpegManager.cs | 21 +-- MediaBrowser.Model/DTO/StreamOptions.cs | 2 + .../HttpServer/HttpServer.cs | 18 +-- .../Library/LibraryManager.cs | 86 ++++++++--- .../Library/UserManager.cs | 41 +++--- ...MediaBrowser.Server.Implementations.csproj | 2 - .../ApplicationHost.cs | 136 ++++++++++++------ .../EntryPoints/LoadRegistrations.cs | 57 ++++++++ .../MediaBrowser.ServerApplication.csproj | 1 + 18 files changed, 341 insertions(+), 215 deletions(-) create mode 100644 MediaBrowser.ServerApplication/EntryPoints/LoadRegistrations.cs diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index 634906afc5..a751278b72 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -23,6 +23,7 @@ namespace MediaBrowser.Api.Playback.Progressive [Route("/Videos/{Id}/stream.mpeg", "GET")] [Route("/Videos/{Id}/stream.avi", "GET")] [Route("/Videos/{Id}/stream.m2ts", "GET")] + [Route("/Videos/{Id}/stream.3gp", "GET")] [Route("/Videos/{Id}/stream", "GET")] [Route("/Videos/{Id}/stream.ts", "HEAD")] [Route("/Videos/{Id}/stream.webm", "HEAD")] @@ -34,6 +35,7 @@ namespace MediaBrowser.Api.Playback.Progressive [Route("/Videos/{Id}/stream.mkv", "HEAD")] [Route("/Videos/{Id}/stream.mpeg", "HEAD")] [Route("/Videos/{Id}/stream.avi", "HEAD")] + [Route("/Videos/{Id}/stream.3gp", "HEAD")] [Route("/Videos/{Id}/stream.m2ts", "HEAD")] [Route("/Videos/{Id}/stream", "HEAD")] [Api(Description = "Gets a video stream")] diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 017f69b626..4b8574c89a 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -195,8 +195,6 @@ namespace MediaBrowser.Common.Implementations Task.Run(() => ConfigureAutoRunAtStartup()); - Task.Run(() => SecurityManager.LoadAllRegistrationInfo()); - ConfigurationManager.ConfigurationUpdated += ConfigurationManager_ConfigurationUpdated; }); } @@ -236,11 +234,6 @@ namespace MediaBrowser.Common.Implementations var assemblies = GetComposablePartAssemblies().ToArray(); - foreach (var assembly in assemblies) - { - Logger.Info("Loading {0}", assembly.FullName); - } - AllTypes = assemblies.SelectMany(GetTypes).ToArray(); AllConcreteTypes = AllTypes.Where(t => t.IsClass && !t.IsAbstract && !t.IsInterface && !t.IsGenericType).ToArray(); @@ -270,19 +263,15 @@ namespace MediaBrowser.Common.Implementations RegisterSingleInstance(TaskManager); HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger); - RegisterSingleInstance(HttpClient); NetworkManager = new NetworkManager(); - RegisterSingleInstance(NetworkManager); SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths); - RegisterSingleInstance(SecurityManager); PackageManager = new PackageManager(SecurityManager, NetworkManager, HttpClient, ApplicationPaths, JsonSerializer, Logger); - RegisterSingleInstance(PackageManager); }); } diff --git a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs index 6ac4d2d5d2..c7c3b3a576 100644 --- a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs +++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs @@ -20,15 +20,15 @@ namespace MediaBrowser.Common.Implementations.Security /// /// The _is MB supporter /// - private bool? _isMBSupporter; + private bool? _isMbSupporter; /// /// The _is MB supporter initialized /// - private bool _isMBSupporterInitialized; + private bool _isMbSupporterInitialized; /// /// The _is MB supporter sync lock /// - private object _isMBSupporterSyncLock = new object(); + private object _isMbSupporterSyncLock = new object(); /// /// Gets a value indicating whether this instance is MB supporter. @@ -38,14 +38,15 @@ namespace MediaBrowser.Common.Implementations.Security { get { - LazyInitializer.EnsureInitialized(ref _isMBSupporter, ref _isMBSupporterInitialized, ref _isMBSupporterSyncLock, () => GetRegistrationStatus("MBSupporter").Result.IsRegistered); - return _isMBSupporter.Value; + LazyInitializer.EnsureInitialized(ref _isMbSupporter, ref _isMbSupporterInitialized, ref _isMbSupporterSyncLock, () => GetRegistrationStatus("MBSupporter").Result.IsRegistered); + return _isMbSupporter.Value; } } - private IHttpClient _httpClient; - private IJsonSerializer _jsonSerializer; - private IApplicationHost _appHost; + private readonly IHttpClient _httpClient; + private readonly IJsonSerializer _jsonSerializer; + private readonly IApplicationHost _appHost; + private readonly IApplicationPaths _applciationPaths; private IEnumerable _registeredEntities; protected IEnumerable RegisteredEntities { @@ -65,10 +66,10 @@ namespace MediaBrowser.Common.Implementations.Security throw new ArgumentNullException("httpClient"); } + _applciationPaths = appPaths; _appHost = appHost; _httpClient = httpClient; _jsonSerializer = jsonSerializer; - MBRegistration.Init(appPaths); } /// @@ -92,6 +93,9 @@ namespace MediaBrowser.Common.Implementations.Security /// Task{MBRegistrationRecord}. public async Task GetRegistrationStatus(string feature, string mb2Equivalent = null) { + // Do this on demend instead of in the constructor to delay the external assembly load + // Todo: Refactor external methods to take app paths as a param + MBRegistration.Init(_applciationPaths); return await MBRegistration.GetRegistrationStatus(_httpClient, _jsonSerializer, feature, mb2Equivalent).ConfigureAwait(false); } @@ -101,9 +105,18 @@ namespace MediaBrowser.Common.Implementations.Security /// The supporter key. public string SupporterKey { - get { return MBRegistration.SupporterKey; } + get + { + // Do this on demend instead of in the constructor to delay the external assembly load + // Todo: Refactor external methods to take app paths as a param + MBRegistration.Init(_applciationPaths); + return MBRegistration.SupporterKey; + } set { + // Do this on demend instead of in the constructor to delay the external assembly load + // Todo: Refactor external methods to take app paths as a param + MBRegistration.Init(_applciationPaths); if (value != MBRegistration.SupporterKey) { MBRegistration.SupporterKey = value; @@ -119,9 +132,18 @@ namespace MediaBrowser.Common.Implementations.Security /// The legacy key. public string LegacyKey { - get { return MBRegistration.LegacyKey; } + get + { + // Do this on demend instead of in the constructor to delay the external assembly load + // Todo: Refactor external methods to take app paths as a param + MBRegistration.Init(_applciationPaths); + return MBRegistration.LegacyKey; + } set { + // Do this on demend instead of in the constructor to delay the external assembly load + // Todo: Refactor external methods to take app paths as a param + MBRegistration.Init(_applciationPaths); if (value != MBRegistration.LegacyKey) { MBRegistration.LegacyKey = value; @@ -136,8 +158,8 @@ namespace MediaBrowser.Common.Implementations.Security /// private void ResetSupporterInfo() { - _isMBSupporter = null; - _isMBSupporterInitialized = false; + _isMbSupporter = null; + _isMbSupporterInitialized = false; } } } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 67ec219bb4..e8e90b97ad 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -668,7 +668,7 @@ namespace MediaBrowser.Controller.Entities return LibraryManager.ResolvePaths