From 7c0f97d56b538418ec80bcfbd04f78d22be49eba Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 16 Aug 2013 14:43:11 -0400 Subject: check for app updates less frequently --- .../BaseApplicationHost.cs | 49 +++++++++++++++++++++- .../ScheduledTasks/Tasks/SystemUpdateTask.cs | 8 ++-- 2 files changed, 51 insertions(+), 6 deletions(-) (limited to 'MediaBrowser.Common.Implementations') 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)} }; } -- cgit v1.2.3