diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 31db86ddf..0bd61dbc2 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -557,14 +557,59 @@ namespace MediaBrowser.Common.Implementations /// true if this instance can self update; otherwise, false. public abstract bool CanSelfUpdate { get; } + private Tuple _lastUpdateCheckResult; + /// /// Checks for update. /// /// The cancellation token. /// The progress. /// Task{CheckForUpdateResult}. - public abstract Task CheckForApplicationUpdate(CancellationToken cancellationToken, - IProgress progress); + public async Task CheckForApplicationUpdate(CancellationToken cancellationToken, + IProgress progress) + { + if (_lastUpdateCheckResult != null) + { + // Let dev users get results more often for testing purposes + var cacheLength = ConfigurationManager.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Dev + ? TimeSpan.FromHours(1) + : TimeSpan.FromHours(12); + + if ((DateTime.UtcNow - _lastUpdateCheckResult.Item2) < cacheLength) + { + return _lastUpdateCheckResult.Item1; + } + } + + var result = await CheckForApplicationUpdateInternal(cancellationToken, progress).ConfigureAwait(false); + + _lastUpdateCheckResult = new Tuple(result, DateTime.UtcNow); + + return _lastUpdateCheckResult.Item1; + } + + /// + /// Checks for application update internal. + /// + /// The cancellation token. + /// The progress. + /// Task{CheckForUpdateResult}. + private async Task CheckForApplicationUpdateInternal(CancellationToken cancellationToken, + IProgress progress) + { + var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None).ConfigureAwait(false); + + var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, ApplicationUpdatePackageName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel); + + return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } : + new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false }; + } + + /// + /// Gets the name of the application update package. + /// + /// The name of the application update package. + protected abstract string ApplicationUpdatePackageName { get; } /// /// Updates the application. diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs index 118939178..0a134b5e5 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs @@ -50,11 +50,11 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks { return new ITaskTrigger[] { - // 1am - new DailyTrigger { TimeOfDay = TimeSpan.FromHours(1) }, + // At startup + new StartupTrigger (), - // Every three hours - new IntervalTrigger { Interval = TimeSpan.FromHours(3)} + // Every so often + new IntervalTrigger { Interval = TimeSpan.FromHours(24)} }; } diff --git a/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs b/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs index 547c870eb..6f3356115 100644 --- a/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs +++ b/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs @@ -42,12 +42,11 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks { return new ITaskTrigger[] { - // 1:30am - new DailyTrigger { TimeOfDay = TimeSpan.FromHours(1.5) }, + // At startup + new StartupTrigger (), - new IntervalTrigger { Interval = TimeSpan.FromHours(3)}, - - new StartupTrigger() + // Every so often + new IntervalTrigger { Interval = TimeSpan.FromHours(24)} }; } diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 2e3037b71..2381d3581 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -7,7 +7,6 @@ using MediaBrowser.Common.Implementations; using MediaBrowser.Common.Implementations.IO; using MediaBrowser.Common.Implementations.ScheduledTasks; using MediaBrowser.Common.Implementations.Updates; -using MediaBrowser.Common.IO; using MediaBrowser.Common.MediaInfo; using MediaBrowser.Common.Net; using MediaBrowser.Controller; @@ -25,11 +24,9 @@ using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Sorting; -using MediaBrowser.IsoMounter; using MediaBrowser.Model.IO; using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.System; -using MediaBrowser.Model.Updates; using MediaBrowser.Providers; using MediaBrowser.Server.Implementations; using MediaBrowser.Server.Implementations.BdInfo; @@ -53,7 +50,6 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; -using System.Threading; using System.Threading.Tasks; namespace MediaBrowser.ServerApplication @@ -652,14 +648,9 @@ namespace MediaBrowser.ServerApplication } } - public override async Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) + protected override string ApplicationUpdatePackageName { - var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(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 } : - new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false }; + get { return Constants.MbServerPkgName; } } } }