diff options
7 files changed, 93 insertions, 12 deletions
diff --git a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs index 778a793a9..81262daf6 100644 --- a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs @@ -43,6 +43,12 @@ namespace MediaBrowser.Common.Implementations.Updates _logger = logger; } + /// <summary> + /// Get all available packages including registration information. + /// Use this for the plug-in catalog to provide all information for this installation. + /// </summary> + /// <param name="cancellationToken"></param> + /// <returns></returns> public async Task<IEnumerable<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken) { var data = new Dictionary<string, string> { { "key", _securityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } }; @@ -52,15 +58,39 @@ namespace MediaBrowser.Common.Implementations.Updates cancellationToken.ThrowIfCancellationRequested(); var packages = _jsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList(); - foreach (var package in packages) + + return FilterVersions(packages); + } + + } + + /// <summary> + /// Get all available packages using the static file resource. + /// Use this for update checks as it will be much less taxing on the server and can be cached. + /// </summary> + /// <param name="cancellationToken"></param> + /// <returns></returns> + public async Task<IEnumerable<PackageInfo>> GetAvailablePackagesStatic(CancellationToken cancellationToken) + { + using (var json = await _httpClient.Get(Constants.Constants.MbAdminUrl + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false)) + { + cancellationToken.ThrowIfCancellationRequested(); + + var packages = _jsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList(); + + return FilterVersions(packages); + } + } + + private IEnumerable<PackageInfo> FilterVersions(List<PackageInfo> original) + { + foreach (var package in original) { package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl)) .OrderByDescending(v => v.version).ToList(); } - return packages; - } - + return original; } public async Task InstallPackage(IProgress<double> progress, PackageVersionInfo package, CancellationToken cancellationToken) diff --git a/MediaBrowser.Common/Updates/IPackageManager.cs b/MediaBrowser.Common/Updates/IPackageManager.cs index ecaf9cef8..4a2db06d1 100644 --- a/MediaBrowser.Common/Updates/IPackageManager.cs +++ b/MediaBrowser.Common/Updates/IPackageManager.cs @@ -9,13 +9,20 @@ namespace MediaBrowser.Common.Updates public interface IPackageManager { /// <summary> - /// Gets all available packages. + /// Gets all available packages dynamically. /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task{List{PackageInfo}}.</returns> Task<IEnumerable<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken); /// <summary> + /// Gets all available packages from a static resource. + /// </summary> + /// <param name="cancellationToken">The cancellation token.</param> + /// <returns>Task{List{PackageInfo}}.</returns> + Task<IEnumerable<PackageInfo>> GetAvailablePackagesStatic(CancellationToken cancellationToken); + + /// <summary> /// Installs a package. /// </summary> /// <param name="progress"></param> diff --git a/MediaBrowser.Controller/Updates/IInstallationManager.cs b/MediaBrowser.Controller/Updates/IInstallationManager.cs index dc6aaf0c9..791150276 100644 --- a/MediaBrowser.Controller/Updates/IInstallationManager.cs +++ b/MediaBrowser.Controller/Updates/IInstallationManager.cs @@ -79,7 +79,7 @@ namespace MediaBrowser.Controller.Updates PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, PackageVersionClass classification = PackageVersionClass.Release); /// <summary> - /// Gets the available plugin updates. + /// Gets the available plugin updates including registration info. /// </summary> /// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param> /// <param name="cancellationToken">The cancellation token.</param> @@ -87,6 +87,14 @@ namespace MediaBrowser.Controller.Updates Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(bool withAutoUpdateEnabled, CancellationToken cancellationToken); /// <summary> + /// Gets the available plugin updates from a static resource (not including registration info). + /// </summary> + /// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param> + /// <param name="cancellationToken">The cancellation token.</param> + /// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns> + Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdatesStatic(bool withAutoUpdateEnabled, CancellationToken cancellationToken); + + /// <summary> /// Installs the package. /// </summary> /// <param name="package">The package.</param> diff --git a/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs b/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs index 9c869ddc1..3a0a86526 100644 --- a/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs +++ b/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs @@ -60,7 +60,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks { progress.Report(0); - var packagesToInstall = (await _installationManager.GetAvailablePluginUpdates(true, cancellationToken).ConfigureAwait(false)).ToList(); + var packagesToInstall = (await _installationManager.GetAvailablePluginUpdatesStatic(true, cancellationToken).ConfigureAwait(false)).ToList(); progress.Report(10); diff --git a/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs index 9c3b532ec..4dd9c47d1 100644 --- a/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs @@ -171,6 +171,26 @@ namespace MediaBrowser.Server.Implementations.Updates { var packages = (await _packageManager.GetAvailablePackages(cancellationToken).ConfigureAwait(false)).ToList(); + return FilterPackages(packages, packageType, applicationVersion); + } + + /// <summary> + /// Gets all available packages. + /// </summary> + /// <param name="cancellationToken">The cancellation token.</param> + /// <param name="packageType">Type of the package.</param> + /// <param name="applicationVersion">The application version.</param> + /// <returns>Task{List{PackageInfo}}.</returns> + protected async Task<IEnumerable<PackageInfo>> GetAvailablePackagesStatic(CancellationToken cancellationToken, + PackageType? packageType = null, + Version applicationVersion = null) + { + var packages = (await _packageManager.GetAvailablePackagesStatic(cancellationToken).ConfigureAwait(false)).ToList(); + return FilterPackages(packages, packageType, applicationVersion); + } + + protected IEnumerable<PackageInfo> FilterPackages(List<PackageInfo> packages, PackageType? packageType, Version applicationVersion) + { if (packageType.HasValue) { packages = packages.Where(p => p.type == packageType.Value).ToList(); @@ -265,7 +285,8 @@ namespace MediaBrowser.Server.Implementations.Updates } /// <summary> - /// Gets the available plugin updates. + /// Gets the available plugin updates including registration information for each one. + /// Used with API and catalog. /// </summary> /// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param> /// <param name="cancellationToken">The cancellation token.</param> @@ -273,7 +294,25 @@ namespace MediaBrowser.Server.Implementations.Updates public async Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(bool withAutoUpdateEnabled, CancellationToken cancellationToken) { var catalog = await GetAvailablePackages(cancellationToken).ConfigureAwait(false); + return FilterCatalog(catalog, withAutoUpdateEnabled); + } + /// <summary> + /// Gets the available plugin updates from a static resource - no registration information. + /// Used for update checks. + /// </summary> + /// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param> + /// <param name="cancellationToken">The cancellation token.</param> + /// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns> + public async Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdatesStatic(bool withAutoUpdateEnabled, CancellationToken cancellationToken) + { + var catalog = await GetAvailablePackagesStatic(cancellationToken).ConfigureAwait(false); + return FilterCatalog(catalog, withAutoUpdateEnabled); + } + + protected IEnumerable<PackageVersionInfo> FilterCatalog(IEnumerable<PackageInfo> catalog, bool withAutoUpdateEnabled) + { + var plugins = ApplicationHost.Plugins; if (withAutoUpdateEnabled) diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 70cd319ca..0d6c5ed35 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -474,7 +474,7 @@ namespace MediaBrowser.ServerApplication /// <returns>Task{CheckForUpdateResult}.</returns> public async override Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress) { - var availablePackages = await PackageManager.GetAvailablePackages(CancellationToken.None).ConfigureAwait(false); + var availablePackages = await PackageManager.GetAvailablePackagesStatic(CancellationToken.None).ConfigureAwait(false); var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel); return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } : diff --git a/MediaBrowser.sln b/MediaBrowser.sln index e6a61c9de..f4a9f3156 100644 --- a/MediaBrowser.sln +++ b/MediaBrowser.sln @@ -221,7 +221,4 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(Performance) = preSolution - HasPerformanceSessions = true - EndGlobalSection EndGlobal |
