You've already forked Sonarr
							
							
				mirror of
				https://github.com/Sonarr/Sonarr.git
				synced 2025-10-31 00:07:55 +02:00 
			
		
		
		
	added log trim command
This commit is contained in:
		| @@ -1,8 +0,0 @@ | ||||
| namespace NzbDrone.Core.Datastore | ||||
| { | ||||
|     public interface IReadModels<T> where T : ModelBase | ||||
|     { | ||||
|         T All(); | ||||
|         T Get(int id); | ||||
|     } | ||||
| } | ||||
| @@ -1,9 +0,0 @@ | ||||
| namespace NzbDrone.Core.Datastore | ||||
| { | ||||
|     public interface IWriteModels<T> where T : ModelBase | ||||
|     { | ||||
|         T Add(T model); | ||||
|         T Update(T model); | ||||
|         void Delete(int id); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,24 @@ | ||||
| using FluentMigrator; | ||||
| using NzbDrone.Core.Datastore.Migration.Framework; | ||||
|  | ||||
| namespace NzbDrone.Core.Datastore.Migration | ||||
| { | ||||
|     [Tags("")] | ||||
|     [Migration(6)] | ||||
|     public class add_index_to_log_time : NzbDroneMigrationBase | ||||
|     { | ||||
|         protected override void LogDbUpgrade() | ||||
|         { | ||||
|             Delete.Table("Logs"); | ||||
|  | ||||
|             Create.TableForModel("Logs") | ||||
|                   .WithColumn("Message").AsString() | ||||
|                   .WithColumn("Time").AsDateTime().Indexed() | ||||
|                   .WithColumn("Logger").AsString() | ||||
|                   .WithColumn("Method").AsString().Nullable() | ||||
|                   .WithColumn("Exception").AsString().Nullable() | ||||
|                   .WithColumn("ExceptionType").AsString().Nullable() | ||||
|                   .WithColumn("Level").AsString(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,7 +1,6 @@ | ||||
| using System; | ||||
| using FluentMigrator.Runner; | ||||
| using NLog; | ||||
| using NzbDrone.Common.Composition; | ||||
|  | ||||
| namespace NzbDrone.Core.Datastore.Migration.Framework | ||||
| { | ||||
|   | ||||
| @@ -14,18 +14,18 @@ namespace NzbDrone.Core.Datastore.Migration.Framework | ||||
|  | ||||
|         public override void Up() | ||||
|         { | ||||
|             if ((MigrationType)ApplicationContext == MigrationType.Main) | ||||
|             switch ((MigrationType)ApplicationContext) | ||||
|             { | ||||
|                 MainDbUpgrade(); | ||||
|             } | ||||
|             else if ((MigrationType)ApplicationContext == MigrationType.Log) | ||||
|             { | ||||
|                 LogDbUpgrade(); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 LogDbUpgrade(); | ||||
|                 MainDbUpgrade(); | ||||
|                 case MigrationType.Main: | ||||
|                     MainDbUpgrade(); | ||||
|                     return; | ||||
|                 case MigrationType.Log: | ||||
|                     LogDbUpgrade(); | ||||
|                     return; | ||||
|                 default: | ||||
|                     LogDbUpgrade(); | ||||
|                     MainDbUpgrade(); | ||||
|                     return; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -1,9 +1,4 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
|  | ||||
| namespace NzbDrone.Core.Datastore | ||||
| namespace NzbDrone.Core.Datastore | ||||
| { | ||||
|     public enum MigrationType | ||||
|     { | ||||
|   | ||||
| @@ -1,6 +1,4 @@ | ||||
| using System.Data; | ||||
| using System.Diagnostics; | ||||
| using Marr.Data; | ||||
| using System.Diagnostics; | ||||
|  | ||||
| namespace NzbDrone.Core.Datastore | ||||
| { | ||||
|   | ||||
| @@ -1,7 +1,4 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Collections.Generic; | ||||
|  | ||||
| namespace NzbDrone.Core.Datastore | ||||
| { | ||||
|   | ||||
| @@ -1,10 +1,6 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.ComponentModel; | ||||
| using System.Linq; | ||||
| using System.Linq.Expressions; | ||||
| using System.Reflection; | ||||
| using System.Text; | ||||
|  | ||||
| namespace NzbDrone.Core.Datastore | ||||
| { | ||||
|   | ||||
| @@ -1,8 +1,6 @@ | ||||
| using System; | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Reflection; | ||||
| using Marr.Data; | ||||
| using Marr.Data.Mapping; | ||||
| using NzbDrone.Core.Configuration; | ||||
|   | ||||
							
								
								
									
										8
									
								
								NzbDrone.Core/Instrumentation/Commands/TrimLogCommand.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								NzbDrone.Core/Instrumentation/Commands/TrimLogCommand.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| using NzbDrone.Common.Messaging; | ||||
|  | ||||
| namespace NzbDrone.Core.Instrumentation.Commands | ||||
| { | ||||
|     public class TrimLogCommand : ICommand | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -1,6 +1,4 @@ | ||||
| using System; | ||||
| using System.Data; | ||||
| using System.Linq; | ||||
| using NzbDrone.Common.Messaging; | ||||
| using NzbDrone.Core.Datastore; | ||||
|  | ||||
| @@ -20,8 +18,8 @@ namespace NzbDrone.Core.Instrumentation | ||||
|  | ||||
|         public void Trim() | ||||
|         { | ||||
|             var oldIds = Query.Where(c => c.Time < DateTime.UtcNow.AddDays(-30).Date).Select(c => c.Id); | ||||
|             DeleteMany(oldIds); | ||||
|             var trimDate = DateTime.UtcNow.AddDays(-15).Date; | ||||
|             Delete(c => c.Time <= trimDate); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,16 +1,15 @@ | ||||
| using System.Linq; | ||||
| using NzbDrone.Common.Messaging; | ||||
| using NzbDrone.Core.Datastore; | ||||
| using NzbDrone.Core.Instrumentation.Commands; | ||||
|  | ||||
| namespace NzbDrone.Core.Instrumentation | ||||
| { | ||||
|     public interface ILogService | ||||
|     { | ||||
|         void DeleteAll(); | ||||
|         void Trim(); | ||||
|         PagingSpec<Log> Paged(PagingSpec<Log> pagingSpec); | ||||
|     } | ||||
|  | ||||
|     public class LogService : ILogService | ||||
|     public class LogService : ILogService, IExecute<TrimLogCommand> | ||||
|     { | ||||
|         private readonly ILogRepository _logRepository; | ||||
|  | ||||
| @@ -19,19 +18,14 @@ namespace NzbDrone.Core.Instrumentation | ||||
|             _logRepository = logRepository; | ||||
|         } | ||||
|  | ||||
|         public void DeleteAll() | ||||
|         { | ||||
|             _logRepository.Purge(); | ||||
|         } | ||||
|  | ||||
|         public void Trim() | ||||
|         { | ||||
|             _logRepository.Trim(); | ||||
|         } | ||||
|  | ||||
|         public PagingSpec<Log> Paged(PagingSpec<Log> pagingSpec) | ||||
|         { | ||||
|             return _logRepository.GetPaged(pagingSpec); | ||||
|         } | ||||
|  | ||||
|         public void Execute(TrimLogCommand message) | ||||
|         { | ||||
|             _logRepository.Trim(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -4,6 +4,7 @@ using System.Linq; | ||||
| using NLog; | ||||
| using NzbDrone.Common.Messaging; | ||||
| using NzbDrone.Core.Indexers; | ||||
| using NzbDrone.Core.Instrumentation.Commands; | ||||
| using NzbDrone.Core.Lifecycle; | ||||
| using NzbDrone.Core.MediaFiles.Commands; | ||||
| using NzbDrone.Core.Providers; | ||||
| @@ -42,7 +43,8 @@ namespace NzbDrone.Core.Jobs | ||||
|                     new ScheduledTask{ Interval = 12*60, TypeName = typeof(UpdateXemMappings).FullName}, | ||||
|                     new ScheduledTask{ Interval = 6*60, TypeName = typeof(RefreshSeriesCommand).FullName}, | ||||
|                     new ScheduledTask{ Interval = 1, TypeName = typeof(DownloadedEpisodesScanCommand).FullName}, | ||||
|                     new ScheduledTask{ Interval = 5, TypeName = typeof(ApplicationUpdateCommand).FullName} | ||||
|                     new ScheduledTask{ Interval = 5, TypeName = typeof(ApplicationUpdateCommand).FullName}, | ||||
|                     new ScheduledTask{ Interval = 1*60, TypeName = typeof(TrimLogCommand).FullName} | ||||
|                 }; | ||||
|  | ||||
|             var currentTasks = _scheduledTaskRepository.All(); | ||||
|   | ||||
| @@ -204,14 +204,13 @@ | ||||
|     <Compile Include="Datastore\Converters\EnumIntConverter.cs" /> | ||||
|     <Compile Include="Datastore\Events\ModelEvent.cs" /> | ||||
|     <Compile Include="Datastore\IEmbeddedDocument.cs" /> | ||||
|     <Compile Include="Datastore\IReadModels.cs" /> | ||||
|     <Compile Include="Datastore\IWriteModels.cs" /> | ||||
|     <Compile Include="Datastore\LazyList.cs" /> | ||||
|     <Compile Include="Datastore\MappingExtensions.cs" /> | ||||
|     <Compile Include="Datastore\Migration\002_remove_tvrage_imdb_unique_constraint.cs" /> | ||||
|     <Compile Include="Datastore\Migration\003_remove_clean_title_from_scene_mapping.cs" /> | ||||
|     <Compile Include="Datastore\Migration\004_updated_history.cs" /> | ||||
|     <Compile Include="Datastore\Migration\005_added_eventtype_to_history.cs" /> | ||||
|     <Compile Include="Datastore\Migration\006_add_index_to_log_time.cs" /> | ||||
|     <Compile Include="Datastore\Migration\Framework\MigrationController.cs" /> | ||||
|     <Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" /> | ||||
|     <Compile Include="Datastore\Migration\Framework\MigrationOptions.cs" /> | ||||
| @@ -255,6 +254,7 @@ | ||||
|     <Compile Include="Indexers\IndexerSettingUpdatedEvent.cs" /> | ||||
|     <Compile Include="Indexers\IndexerWithSetting.cs" /> | ||||
|     <Compile Include="Indexers\RssSyncCommand.cs" /> | ||||
|     <Compile Include="Instrumentation\Commands\TrimLogCommand.cs" /> | ||||
|     <Compile Include="Jobs\TaskManager.cs" /> | ||||
|     <Compile Include="Lifecycle\ApplicationShutdownRequested.cs" /> | ||||
|     <Compile Include="MediaCover\CoverAlreadyExistsSpecification.cs" /> | ||||
|   | ||||
| @@ -2,6 +2,7 @@ | ||||
|   <FileVersion>1</FileVersion> | ||||
|   <AutoEnableOnStartup>False</AutoEnableOnStartup> | ||||
|   <AllowParallelTestExecution>true</AllowParallelTestExecution> | ||||
|   <AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves> | ||||
|   <FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit> | ||||
|   <FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio> | ||||
|   <FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user