From 55bbfc2dcc6431c1d2b6320c47a600e98a7adc1d Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Thu, 27 Jun 2013 15:08:57 -0400 Subject: [PATCH] Change update checks to use static file --- .../Updates/PackageManager.cs | 38 +++++++++++++++-- .../Updates/IPackageManager.cs | 9 +++- .../Updates/IInstallationManager.cs | 10 ++++- .../ScheduledTasks/PluginUpdateTask.cs | 2 +- .../Updates/InstallationManager.cs | 41 ++++++++++++++++++- .../ApplicationHost.cs | 2 +- MediaBrowser.sln | 3 -- 7 files changed, 93 insertions(+), 12 deletions(-) diff --git a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs index 778a793a94..81262daf69 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; } + /// + /// Get all available packages including registration information. + /// Use this for the plug-in catalog to provide all information for this installation. + /// + /// + /// public async Task> GetAvailablePackages(CancellationToken cancellationToken) { var data = new Dictionary { { "key", _securityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } }; @@ -52,15 +58,39 @@ namespace MediaBrowser.Common.Implementations.Updates cancellationToken.ThrowIfCancellationRequested(); var packages = _jsonSerializer.DeserializeFromStream>(json).ToList(); - foreach (var package in packages) + + return FilterVersions(packages); + } + + } + + /// + /// 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. + /// + /// + /// + public async Task> GetAvailablePackagesStatic(CancellationToken cancellationToken) + { + using (var json = await _httpClient.Get(Constants.Constants.MbAdminUrl + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false)) + { + cancellationToken.ThrowIfCancellationRequested(); + + var packages = _jsonSerializer.DeserializeFromStream>(json).ToList(); + + return FilterVersions(packages); + } + } + + private IEnumerable FilterVersions(List 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 progress, PackageVersionInfo package, CancellationToken cancellationToken) diff --git a/MediaBrowser.Common/Updates/IPackageManager.cs b/MediaBrowser.Common/Updates/IPackageManager.cs index ecaf9cef83..4a2db06d1f 100644 --- a/MediaBrowser.Common/Updates/IPackageManager.cs +++ b/MediaBrowser.Common/Updates/IPackageManager.cs @@ -9,12 +9,19 @@ namespace MediaBrowser.Common.Updates public interface IPackageManager { /// - /// Gets all available packages. + /// Gets all available packages dynamically. /// /// The cancellation token. /// Task{List{PackageInfo}}. Task> GetAvailablePackages(CancellationToken cancellationToken); + /// + /// Gets all available packages from a static resource. + /// + /// The cancellation token. + /// Task{List{PackageInfo}}. + Task> GetAvailablePackagesStatic(CancellationToken cancellationToken); + /// /// Installs a package. /// diff --git a/MediaBrowser.Controller/Updates/IInstallationManager.cs b/MediaBrowser.Controller/Updates/IInstallationManager.cs index dc6aaf0c9f..7911502760 100644 --- a/MediaBrowser.Controller/Updates/IInstallationManager.cs +++ b/MediaBrowser.Controller/Updates/IInstallationManager.cs @@ -79,13 +79,21 @@ namespace MediaBrowser.Controller.Updates PackageVersionInfo GetLatestCompatibleVersion(IEnumerable availablePackages, string name, PackageVersionClass classification = PackageVersionClass.Release); /// - /// Gets the available plugin updates. + /// Gets the available plugin updates including registration info. /// /// if set to true [with auto update enabled]. /// The cancellation token. /// Task{IEnumerable{PackageVersionInfo}}. Task> GetAvailablePluginUpdates(bool withAutoUpdateEnabled, CancellationToken cancellationToken); + /// + /// Gets the available plugin updates from a static resource (not including registration info). + /// + /// if set to true [with auto update enabled]. + /// The cancellation token. + /// Task{IEnumerable{PackageVersionInfo}}. + Task> GetAvailablePluginUpdatesStatic(bool withAutoUpdateEnabled, CancellationToken cancellationToken); + /// /// Installs the package. /// diff --git a/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs b/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs index 9c869ddc18..3a0a865263 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 9c3b532eca..4dd9c47d1e 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); + } + + /// + /// Gets all available packages. + /// + /// The cancellation token. + /// Type of the package. + /// The application version. + /// Task{List{PackageInfo}}. + protected async Task> 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 FilterPackages(List 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 } /// - /// Gets the available plugin updates. + /// Gets the available plugin updates including registration information for each one. + /// Used with API and catalog. /// /// if set to true [with auto update enabled]. /// The cancellation token. @@ -273,7 +294,25 @@ namespace MediaBrowser.Server.Implementations.Updates public async Task> GetAvailablePluginUpdates(bool withAutoUpdateEnabled, CancellationToken cancellationToken) { var catalog = await GetAvailablePackages(cancellationToken).ConfigureAwait(false); + return FilterCatalog(catalog, withAutoUpdateEnabled); + } + /// + /// Gets the available plugin updates from a static resource - no registration information. + /// Used for update checks. + /// + /// if set to true [with auto update enabled]. + /// The cancellation token. + /// Task{IEnumerable{PackageVersionInfo}}. + public async Task> GetAvailablePluginUpdatesStatic(bool withAutoUpdateEnabled, CancellationToken cancellationToken) + { + var catalog = await GetAvailablePackagesStatic(cancellationToken).ConfigureAwait(false); + return FilterCatalog(catalog, withAutoUpdateEnabled); + } + + protected IEnumerable FilterCatalog(IEnumerable catalog, bool withAutoUpdateEnabled) + { + var plugins = ApplicationHost.Plugins; if (withAutoUpdateEnabled) diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 70cd319ca6..0d6c5ed358 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -474,7 +474,7 @@ namespace MediaBrowser.ServerApplication /// Task{CheckForUpdateResult}. public async override Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress 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 e6a61c9de1..f4a9f31569 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