mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-10-01 16:06:24 +02:00
Automatic History cleanup setting
This commit is contained in:
@@ -77,28 +77,16 @@ namespace NzbDrone.Core.Configuration
|
||||
return _repository.Get(key.ToLower()) != null;
|
||||
}
|
||||
|
||||
public bool AutoUnmonitorPreviouslyDownloadedMovies
|
||||
{
|
||||
get { return GetValueBoolean("AutoUnmonitorPreviouslyDownloadedMovies"); }
|
||||
set { SetValue("AutoUnmonitorPreviouslyDownloadedMovies", value); }
|
||||
}
|
||||
|
||||
public int Retention
|
||||
{
|
||||
get { return GetValueInt("Retention", 0); }
|
||||
set { SetValue("Retention", value); }
|
||||
}
|
||||
|
||||
public string RecycleBin
|
||||
public int HistoryCleanupDays
|
||||
{
|
||||
get { return GetValue("RecycleBin", string.Empty); }
|
||||
set { SetValue("RecycleBin", value); }
|
||||
}
|
||||
|
||||
public int RecycleBinCleanupDays
|
||||
{
|
||||
get { return GetValueInt("RecycleBinCleanupDays", 7); }
|
||||
set { SetValue("RecycleBinCleanupDays", value); }
|
||||
get { return GetValueInt("HistoryCleanupDays", 365); }
|
||||
set { SetValue("HistoryCleanupDays", value); }
|
||||
}
|
||||
|
||||
public int RssSyncInterval
|
||||
@@ -202,20 +190,6 @@ namespace NzbDrone.Core.Configuration
|
||||
set { SetValue("RemoveFailedDownloads", value); }
|
||||
}
|
||||
|
||||
public bool CreateEmptyMovieFolders
|
||||
{
|
||||
get { return GetValueBoolean("CreateEmptyMovieFolders", false); }
|
||||
|
||||
set { SetValue("CreateEmptyMovieFolders", value); }
|
||||
}
|
||||
|
||||
public bool DeleteEmptyFolders
|
||||
{
|
||||
get { return GetValueBoolean("DeleteEmptyFolders", false); }
|
||||
|
||||
set { SetValue("DeleteEmptyFolders", value); }
|
||||
}
|
||||
|
||||
public string DownloadClientWorkingFolders
|
||||
{
|
||||
get { return GetValue("DownloadClientWorkingFolders", "_UNPACK_|_FAILED_"); }
|
||||
@@ -236,76 +210,6 @@ namespace NzbDrone.Core.Configuration
|
||||
set { SetValue("DownloadClientHistoryLimit", value); }
|
||||
}
|
||||
|
||||
public bool SkipFreeSpaceCheckWhenImporting
|
||||
{
|
||||
get { return GetValueBoolean("SkipFreeSpaceCheckWhenImporting", false); }
|
||||
|
||||
set { SetValue("SkipFreeSpaceCheckWhenImporting", value); }
|
||||
}
|
||||
|
||||
public int MinimumFreeSpaceWhenImporting
|
||||
{
|
||||
get { return GetValueInt("MinimumFreeSpaceWhenImporting", 100); }
|
||||
|
||||
set { SetValue("MinimumFreeSpaceWhenImporting", value); }
|
||||
}
|
||||
|
||||
public bool CopyUsingHardlinks
|
||||
{
|
||||
get { return GetValueBoolean("CopyUsingHardlinks", true); }
|
||||
|
||||
set { SetValue("CopyUsingHardlinks", value); }
|
||||
}
|
||||
|
||||
public bool EnableMediaInfo
|
||||
{
|
||||
get { return GetValueBoolean("EnableMediaInfo", true); }
|
||||
|
||||
set { SetValue("EnableMediaInfo", value); }
|
||||
}
|
||||
|
||||
public bool ImportExtraFiles
|
||||
{
|
||||
get { return GetValueBoolean("ImportExtraFiles", false); }
|
||||
|
||||
set { SetValue("ImportExtraFiles", value); }
|
||||
}
|
||||
|
||||
public string ExtraFileExtensions
|
||||
{
|
||||
get { return GetValue("ExtraFileExtensions", "srt"); }
|
||||
|
||||
set { SetValue("ExtraFileExtensions", value); }
|
||||
}
|
||||
|
||||
public bool AutoRenameFolders
|
||||
{
|
||||
get { return GetValueBoolean("AutoRenameFolders", false); }
|
||||
|
||||
set { SetValue("AutoRenameFolders", value); }
|
||||
}
|
||||
|
||||
public RescanAfterRefreshType RescanAfterRefresh
|
||||
{
|
||||
get { return GetValueEnum("RescanAfterRefresh", RescanAfterRefreshType.Always); }
|
||||
|
||||
set { SetValue("RescanAfterRefresh", value); }
|
||||
}
|
||||
|
||||
public bool SetPermissionsLinux
|
||||
{
|
||||
get { return GetValueBoolean("SetPermissionsLinux", false); }
|
||||
|
||||
set { SetValue("SetPermissionsLinux", value); }
|
||||
}
|
||||
|
||||
public string FileChmod
|
||||
{
|
||||
get { return GetValue("FileChmod", "0644"); }
|
||||
|
||||
set { SetValue("FileChmod", value); }
|
||||
}
|
||||
|
||||
public int FirstDayOfWeek
|
||||
{
|
||||
get { return GetValueInt("FirstDayOfWeek", (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); }
|
||||
|
@@ -22,24 +22,8 @@ namespace NzbDrone.Core.Configuration
|
||||
bool AutoRedownloadFailed { get; set; }
|
||||
bool RemoveFailedDownloads { get; set; }
|
||||
|
||||
//Media Management
|
||||
bool AutoUnmonitorPreviouslyDownloadedMovies { get; set; }
|
||||
string RecycleBin { get; set; }
|
||||
int RecycleBinCleanupDays { get; set; }
|
||||
bool CreateEmptyMovieFolders { get; set; }
|
||||
bool DeleteEmptyFolders { get; set; }
|
||||
bool SkipFreeSpaceCheckWhenImporting { get; set; }
|
||||
int MinimumFreeSpaceWhenImporting { get; set; }
|
||||
bool CopyUsingHardlinks { get; set; }
|
||||
bool EnableMediaInfo { get; set; }
|
||||
bool ImportExtraFiles { get; set; }
|
||||
string ExtraFileExtensions { get; set; }
|
||||
RescanAfterRefreshType RescanAfterRefresh { get; set; }
|
||||
bool AutoRenameFolders { get; set; }
|
||||
|
||||
//Permissions (Media Management)
|
||||
bool SetPermissionsLinux { get; set; }
|
||||
string FileChmod { get; set; }
|
||||
//History
|
||||
int HistoryCleanupDays { get; set; }
|
||||
|
||||
//Indexers
|
||||
int Retention { get; set; }
|
||||
|
8
src/NzbDrone.Core/History/CleanupHistoryCommand.cs
Normal file
8
src/NzbDrone.Core/History/CleanupHistoryCommand.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
|
||||
namespace NzbDrone.Core.History
|
||||
{
|
||||
public class CleanUpHistoryCommand : Command
|
||||
{
|
||||
}
|
||||
}
|
@@ -26,6 +26,6 @@ namespace NzbDrone.Core.History
|
||||
IndexerQuery = 2,
|
||||
IndexerRss = 3,
|
||||
IndexerAuth = 4,
|
||||
IndexerCapabilities = 5
|
||||
IndexerInfo = 5
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ namespace NzbDrone.Core.History
|
||||
void DeleteForIndexers(List<int> indexerIds);
|
||||
History MostRecentForIndexer(int indexerId);
|
||||
List<History> Since(DateTime date, HistoryEventType? eventType);
|
||||
void Cleanup(int days);
|
||||
}
|
||||
|
||||
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
|
||||
@@ -61,6 +62,11 @@ namespace NzbDrone.Core.History
|
||||
Delete(c => indexerIds.Contains(c.IndexerId));
|
||||
}
|
||||
|
||||
public void Cleanup(int days)
|
||||
{
|
||||
Delete(c => c.Date.AddDays(days) <= DateTime.Now);
|
||||
}
|
||||
|
||||
public History MostRecentForIndexer(int indexerId)
|
||||
{
|
||||
return Query(x => x.IndexerId == indexerId)
|
||||
|
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Indexers.Events;
|
||||
@@ -29,14 +30,17 @@ namespace NzbDrone.Core.History
|
||||
IHandle<ProviderDeletedEvent<IIndexer>>,
|
||||
IHandle<IndexerQueryEvent>,
|
||||
IHandle<IndexerDownloadEvent>,
|
||||
IHandle<IndexerAuthEvent>
|
||||
IHandle<IndexerAuthEvent>,
|
||||
IExecute<CleanUpHistoryCommand>
|
||||
{
|
||||
private readonly IHistoryRepository _historyRepository;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public HistoryService(IHistoryRepository historyRepository, Logger logger)
|
||||
public HistoryService(IHistoryRepository historyRepository, IConfigService configService, Logger logger)
|
||||
{
|
||||
_historyRepository = historyRepository;
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -85,6 +89,23 @@ namespace NzbDrone.Core.History
|
||||
return _historyRepository.Since(date, eventType);
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
var cleanupDays = _configService.HistoryCleanupDays;
|
||||
|
||||
if (cleanupDays == 0)
|
||||
{
|
||||
_logger.Info("Automatic cleanup of History is disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.Info("Removing items older than {0} days from the history", cleanupDays);
|
||||
|
||||
_historyRepository.Cleanup(cleanupDays);
|
||||
|
||||
_logger.Debug("History has been cleaned up.");
|
||||
}
|
||||
|
||||
public void Handle(IndexerQueryEvent message)
|
||||
{
|
||||
var history = new History
|
||||
@@ -171,5 +192,10 @@ namespace NzbDrone.Core.History
|
||||
{
|
||||
_historyRepository.DeleteForIndexers(new List<int> { message.ProviderId });
|
||||
}
|
||||
|
||||
public void Execute(CleanUpHistoryCommand message)
|
||||
{
|
||||
Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ using NzbDrone.Core.Applications;
|
||||
using NzbDrone.Core.Backup;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.HealthCheck;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Housekeeping;
|
||||
using NzbDrone.Core.IndexerVersions;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
@@ -61,6 +62,7 @@ namespace NzbDrone.Core.Jobs
|
||||
new ScheduledTask { Interval = 6 * 60, TypeName = typeof(ApplicationCheckUpdateCommand).FullName },
|
||||
new ScheduledTask { Interval = 6 * 60, TypeName = typeof(CheckHealthCommand).FullName },
|
||||
new ScheduledTask { Interval = 24 * 60, TypeName = typeof(HousekeepingCommand).FullName },
|
||||
new ScheduledTask { Interval = 24 * 60, TypeName = typeof(CleanUpHistoryCommand).FullName },
|
||||
new ScheduledTask { Interval = 24 * 60, TypeName = typeof(IndexerDefinitionUpdateCommand).FullName },
|
||||
new ScheduledTask { Interval = 6 * 60, TypeName = typeof(ApplicationIndexerSyncCommand).FullName },
|
||||
|
||||
@@ -106,40 +108,6 @@ namespace NzbDrone.Core.Jobs
|
||||
return interval * 60 * 24;
|
||||
}
|
||||
|
||||
private int GetRssSyncInterval()
|
||||
{
|
||||
var interval = _configService.RssSyncInterval;
|
||||
|
||||
if (interval > 0 && interval < 10)
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
if (interval < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return interval;
|
||||
}
|
||||
|
||||
private int GetImportListSyncInterval()
|
||||
{
|
||||
var interval = _configService.ImportListSyncInterval;
|
||||
|
||||
if (interval > 0 && interval < 10)
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
if (interval < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return interval;
|
||||
}
|
||||
|
||||
public void Handle(CommandExecutedEvent message)
|
||||
{
|
||||
var scheduledTask = _scheduledTaskRepository.All().SingleOrDefault(c => c.TypeName == message.Command.Body.GetType().FullName);
|
||||
|
@@ -40,6 +40,7 @@ namespace Prowlarr.Api.V1.Config
|
||||
public string BackupFolder { get; set; }
|
||||
public int BackupInterval { get; set; }
|
||||
public int BackupRetention { get; set; }
|
||||
public int HistoryCleanupDays { get; set; }
|
||||
}
|
||||
|
||||
public static class HostConfigResourceMapper
|
||||
@@ -80,7 +81,8 @@ namespace Prowlarr.Api.V1.Config
|
||||
CertificateValidation = configService.CertificateValidation,
|
||||
BackupFolder = configService.BackupFolder,
|
||||
BackupInterval = configService.BackupInterval,
|
||||
BackupRetention = configService.BackupRetention
|
||||
BackupRetention = configService.BackupRetention,
|
||||
HistoryCleanupDays = configService.HistoryCleanupDays
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -1,27 +0,0 @@
|
||||
using FluentValidation;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Validation;
|
||||
using NzbDrone.Core.Validation.Paths;
|
||||
using Prowlarr.Http;
|
||||
|
||||
namespace Prowlarr.Api.V1.Config
|
||||
{
|
||||
[V1ApiController("config/mediamanagement")]
|
||||
public class MediaManagementConfigController : ConfigController<MediaManagementConfigResource>
|
||||
{
|
||||
public MediaManagementConfigController(IConfigService configService, PathExistsValidator pathExistsValidator, FileChmodValidator fileChmodValidator)
|
||||
: base(configService)
|
||||
{
|
||||
SharedValidator.RuleFor(c => c.RecycleBinCleanupDays).GreaterThanOrEqualTo(0);
|
||||
SharedValidator.RuleFor(c => c.FileChmod).SetValidator(fileChmodValidator).When(c => !string.IsNullOrEmpty(c.FileChmod) && (OsInfo.IsLinux || OsInfo.IsOsx));
|
||||
SharedValidator.RuleFor(c => c.RecycleBin).IsValidPath().SetValidator(pathExistsValidator).When(c => !string.IsNullOrWhiteSpace(c.RecycleBin));
|
||||
SharedValidator.RuleFor(c => c.MinimumFreeSpaceWhenImporting).GreaterThanOrEqualTo(100);
|
||||
}
|
||||
|
||||
protected override MediaManagementConfigResource ToResource(IConfigService model)
|
||||
{
|
||||
return MediaManagementConfigResourceMapper.ToResource(model);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
using NzbDrone.Core.Configuration;
|
||||
using Prowlarr.Http.REST;
|
||||
|
||||
namespace Prowlarr.Api.V1.Config
|
||||
{
|
||||
public class MediaManagementConfigResource : RestResource
|
||||
{
|
||||
public bool AutoUnmonitorPreviouslyDownloadedMovies { get; set; }
|
||||
public string RecycleBin { get; set; }
|
||||
public int RecycleBinCleanupDays { get; set; }
|
||||
public bool CreateEmptyMovieFolders { get; set; }
|
||||
public bool DeleteEmptyFolders { get; set; }
|
||||
public RescanAfterRefreshType RescanAfterRefresh { get; set; }
|
||||
public bool AutoRenameFolders { get; set; }
|
||||
public bool PathsDefaultStatic { get; set; }
|
||||
|
||||
public bool SetPermissionsLinux { get; set; }
|
||||
public string FileChmod { get; set; }
|
||||
|
||||
public bool SkipFreeSpaceCheckWhenImporting { get; set; }
|
||||
public int MinimumFreeSpaceWhenImporting { get; set; }
|
||||
public bool CopyUsingHardlinks { get; set; }
|
||||
public bool ImportExtraFiles { get; set; }
|
||||
public string ExtraFileExtensions { get; set; }
|
||||
public bool EnableMediaInfo { get; set; }
|
||||
}
|
||||
|
||||
public static class MediaManagementConfigResourceMapper
|
||||
{
|
||||
public static MediaManagementConfigResource ToResource(IConfigService model)
|
||||
{
|
||||
return new MediaManagementConfigResource
|
||||
{
|
||||
AutoUnmonitorPreviouslyDownloadedMovies = model.AutoUnmonitorPreviouslyDownloadedMovies,
|
||||
RecycleBin = model.RecycleBin,
|
||||
RecycleBinCleanupDays = model.RecycleBinCleanupDays,
|
||||
CreateEmptyMovieFolders = model.CreateEmptyMovieFolders,
|
||||
DeleteEmptyFolders = model.DeleteEmptyFolders,
|
||||
RescanAfterRefresh = model.RescanAfterRefresh,
|
||||
AutoRenameFolders = model.AutoRenameFolders,
|
||||
|
||||
SetPermissionsLinux = model.SetPermissionsLinux,
|
||||
FileChmod = model.FileChmod,
|
||||
|
||||
SkipFreeSpaceCheckWhenImporting = model.SkipFreeSpaceCheckWhenImporting,
|
||||
MinimumFreeSpaceWhenImporting = model.MinimumFreeSpaceWhenImporting,
|
||||
CopyUsingHardlinks = model.CopyUsingHardlinks,
|
||||
ImportExtraFiles = model.ImportExtraFiles,
|
||||
ExtraFileExtensions = model.ExtraFileExtensions,
|
||||
EnableMediaInfo = model.EnableMediaInfo
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user