Browse Source

Change update checks to use static file

Eric Reed 12 years ago
parent
commit
55bbfc2dcc

+ 34 - 4
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)

+ 8 - 1
MediaBrowser.Common/Updates/IPackageManager.cs

@@ -9,12 +9,19 @@ 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>

+ 9 - 1
MediaBrowser.Controller/Updates/IInstallationManager.cs

@@ -79,13 +79,21 @@ 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>
         /// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns>
         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>

+ 1 - 1
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);
 

+ 40 - 1
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)

+ 1 - 1
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 } :

+ 0 - 3
MediaBrowser.sln

@@ -221,7 +221,4 @@ Global
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
 	EndGlobalSection
-	GlobalSection(Performance) = preSolution
-		HasPerformanceSessions = true
-	EndGlobalSection
 EndGlobal