1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-24 08:42:19 +02:00

Added active detection for updatecheck so we know which os/runtime versions don't need to be supported anymore.

This commit is contained in:
Taloth Saldono 2019-08-24 14:54:12 +02:00
parent 6593575850
commit 63853494f8
2 changed files with 43 additions and 12 deletions

View File

@ -1,22 +1,40 @@
using NzbDrone.Common.EnvironmentInfo;
using System;
using System.Linq;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.History;
namespace NzbDrone.Core.Analytics
{
public interface IAnalyticsService
{
bool IsEnabled { get; }
bool InstallIsActive { get; }
}
public class AnalyticsService : IAnalyticsService
{
private readonly IConfigFileProvider _configFileProvider;
private readonly IHistoryService _historyService;
public AnalyticsService(IConfigFileProvider configFileProvider)
public AnalyticsService(IHistoryService historyService, IConfigFileProvider configFileProvider)
{
_configFileProvider = configFileProvider;
_historyService = historyService;
}
public bool IsEnabled => _configFileProvider.AnalyticsEnabled && RuntimeInfo.IsProduction;
public bool InstallIsActive
{
get
{
var lastRecord = _historyService.Paged(new PagingSpec<History.History>() { Page = 0, PageSize = 1, SortKey = "date", SortDirection = SortDirection.Descending });
var monthAgo = DateTime.UtcNow.AddMonths(-1);
return lastRecord.Records.Any(v => v.Date > monthAgo);
}
}
}
}
}

View File

@ -3,6 +3,7 @@
using NzbDrone.Common.Cloud;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Http;
using NzbDrone.Core.Analytics;
namespace NzbDrone.Core.Update
{
@ -15,14 +16,16 @@ public interface IUpdatePackageProvider
public class UpdatePackageProvider : IUpdatePackageProvider
{
private readonly IHttpClient _httpClient;
private readonly IPlatformInfo _platformInfo;
private readonly IHttpRequestBuilderFactory _requestBuilder;
private readonly IPlatformInfo _platformInfo;
private readonly IAnalyticsService _analyticsService;
public UpdatePackageProvider(IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder, IPlatformInfo platformInfo)
public UpdatePackageProvider(IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder, IAnalyticsService analyticsService, IPlatformInfo platformInfo)
{
_httpClient = httpClient;
_platformInfo = platformInfo;
_analyticsService = analyticsService;
_requestBuilder = requestBuilder.Services;
_httpClient = httpClient;
}
public UpdatePackage GetLatestUpdate(string branch, Version currentVersion)
@ -32,10 +35,15 @@ public UpdatePackage GetLatestUpdate(string branch, Version currentVersion)
.AddQueryParam("version", currentVersion)
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
.AddQueryParam("runtimeVer", _platformInfo.Version)
.SetSegment("branch", branch)
.Build();
.SetSegment("branch", branch);
var update = _httpClient.Get<UpdatePackageAvailable>(request).Resource;
if (_analyticsService.IsEnabled)
{
// Send if the system is active so we know which versions to deprecate/ignore
request.AddQueryParam("active", _analyticsService.InstallIsActive.ToString().ToLower());
}
var update = _httpClient.Get<UpdatePackageAvailable>(request.Build()).Resource;
if (!update.Available) return null;
@ -49,10 +57,15 @@ public List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersio
.AddQueryParam("version", currentVersion)
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
.AddQueryParam("runtimeVer", _platformInfo.Version)
.SetSegment("branch", branch)
.Build();
.SetSegment("branch", branch);
var updates = _httpClient.Get<List<UpdatePackage>>(request);
if (_analyticsService.IsEnabled)
{
// Send if the system is active so we know which versions to deprecate/ignore
request.AddQueryParam("active", _analyticsService.InstallIsActive.ToString().ToLower());
}
var updates = _httpClient.Get<List<UpdatePackage>>(request.Build());
return updates.Resource;
}