1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-27 22:57:09 -04:00

New: Show previously installed version in Updates UI

Co-Authored-By: Taloth <Taloth@users.noreply.github.com>
This commit is contained in:
Qstick
2021-01-24 23:33:54 -05:00
parent c892b827af
commit 553a8f2a0a
18 changed files with 317 additions and 11 deletions
@@ -0,0 +1,17 @@
using System;
using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.Update.History.Events
{
public class UpdateInstalledEvent : IEvent
{
public Version PreviousVerison { get; set; }
public Version NewVersion { get; set; }
public UpdateInstalledEvent(Version previousVersion, Version newVersion)
{
PreviousVerison = previousVersion;
NewVersion = newVersion;
}
}
}
@@ -0,0 +1,12 @@
using System;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Update.History
{
public class UpdateHistory : ModelBase
{
public DateTime Date { get; set; }
public Version Version { get; set; }
public UpdateHistoryEventType EventType { get; set; }
}
}
@@ -0,0 +1,9 @@
namespace NzbDrone.Core.Update.History
{
public enum UpdateHistoryEventType
{
Unknown = 0,
Initiated = 1,
Installed = 2
}
}
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Update.History
{
public interface IUpdateHistoryRepository : IBasicRepository<UpdateHistory>
{
UpdateHistory LastInstalled();
UpdateHistory PreviouslyInstalled();
List<UpdateHistory> InstalledSince(DateTime dateTime);
}
public class UpdateHistoryRepository : BasicRepository<UpdateHistory>, IUpdateHistoryRepository
{
public UpdateHistoryRepository(ILogDatabase logDatabase, IEventAggregator eventAggregator)
: base(logDatabase, eventAggregator)
{
}
public UpdateHistory LastInstalled()
{
var history = Query(x => x.EventType == UpdateHistoryEventType.Installed)
.OrderBy(v => v.Date)
.Take(1)
.FirstOrDefault();
return history;
}
public UpdateHistory PreviouslyInstalled()
{
var history = Query(x => x.EventType == UpdateHistoryEventType.Installed)
.OrderBy(v => v.Date)
.Skip(1)
.Take(1)
.FirstOrDefault();
return history;
}
public List<UpdateHistory> InstalledSince(DateTime dateTime)
{
var history = Query(v => v.EventType == UpdateHistoryEventType.Installed && v.Date >= dateTime)
.OrderBy(v => v.Date)
.ToList();
return history;
}
}
}
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Update.History.Events;
namespace NzbDrone.Core.Update.History
{
public interface IUpdateHistoryService
{
Version PreviouslyInstalled();
List<UpdateHistory> InstalledSince(DateTime dateTime);
}
public class UpdateHistoryService : IUpdateHistoryService, IHandle<ApplicationStartedEvent>, IHandleAsync<ApplicationStartedEvent>
{
private readonly IUpdateHistoryRepository _repository;
private readonly IEventAggregator _eventAggregator;
private Version _prevVersion;
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator)
{
_repository = repository;
_eventAggregator = eventAggregator;
}
public Version PreviouslyInstalled()
{
var history = _repository.PreviouslyInstalled();
return history?.Version;
}
public List<UpdateHistory> InstalledSince(DateTime dateTime)
{
return _repository.InstalledSince(dateTime);
}
public void Handle(ApplicationStartedEvent message)
{
if (BuildInfo.Version.Major == 10)
{
// Don't save dev versions, they change constantly
return;
}
var history = _repository.LastInstalled();
if (history == null || history.Version != BuildInfo.Version)
{
_prevVersion = history.Version;
_repository.Insert(new UpdateHistory
{
Date = DateTime.UtcNow,
Version = BuildInfo.Version,
EventType = UpdateHistoryEventType.Installed
});
}
}
public void HandleAsync(ApplicationStartedEvent message)
{
if (_prevVersion != null)
{
_eventAggregator.PublishEvent(new UpdateInstalledEvent(_prevVersion, BuildInfo.Version));
}
}
}
}
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Update.History;
namespace NzbDrone.Core.Update
{
@@ -13,18 +15,23 @@ namespace NzbDrone.Core.Update
{
private readonly IConfigFileProvider _configFileProvider;
private readonly IUpdatePackageProvider _updatePackageProvider;
private readonly IUpdateHistoryService _updateHistoryService;
public RecentUpdateProvider(IConfigFileProvider configFileProvider,
IUpdatePackageProvider updatePackageProvider)
IUpdatePackageProvider updatePackageProvider,
IUpdateHistoryService updateHistoryService)
{
_configFileProvider = configFileProvider;
_updatePackageProvider = updatePackageProvider;
_updateHistoryService = updateHistoryService;
}
public List<UpdatePackage> GetRecentUpdatePackages()
{
var branch = _configFileProvider.Branch;
return _updatePackageProvider.GetRecentUpdates(branch, BuildInfo.Version);
var version = BuildInfo.Version;
var prevVersion = _updateHistoryService.PreviouslyInstalled();
return _updatePackageProvider.GetRecentUpdates(branch, version, prevVersion);
}
}
}
@@ -11,7 +11,7 @@ namespace NzbDrone.Core.Update
public interface IUpdatePackageProvider
{
UpdatePackage GetLatestUpdate(string branch, Version currentVersion);
List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersion);
List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersion, Version previousVersion = null);
}
public class UpdatePackageProvider : IUpdatePackageProvider
@@ -56,7 +56,7 @@ namespace NzbDrone.Core.Update
return update.UpdatePackage;
}
public List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersion)
public List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersion, Version previousVersion)
{
var request = _requestBuilder.Create()
.Resource("/update/{branch}/changes")
@@ -67,6 +67,11 @@ namespace NzbDrone.Core.Update
.AddQueryParam("runtimeVer", _platformInfo.Version)
.SetSegment("branch", branch);
if (previousVersion != null && previousVersion != currentVersion)
{
request.AddQueryParam("prevVersion", previousVersion);
}
if (_analyticsService.IsEnabled)
{
// Send if the system is active so we know which versions to deprecate/ignore