1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 04:22:30 +01:00

added log trim command

This commit is contained in:
Keivan Beigi 2013-06-18 18:01:08 -07:00
parent 279f8b5d73
commit 73f3459264
16 changed files with 62 additions and 69 deletions

View File

@ -1,8 +0,0 @@
namespace NzbDrone.Core.Datastore
{
public interface IReadModels<T> where T : ModelBase
{
T All();
T Get(int id);
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}
}

View File

@ -1,7 +1,6 @@
using System; using System;
using FluentMigrator.Runner; using FluentMigrator.Runner;
using NLog; using NLog;
using NzbDrone.Common.Composition;
namespace NzbDrone.Core.Datastore.Migration.Framework namespace NzbDrone.Core.Datastore.Migration.Framework
{ {

View File

@ -14,18 +14,18 @@ protected virtual void LogDbUpgrade()
public override void Up() public override void Up()
{ {
if ((MigrationType)ApplicationContext == MigrationType.Main) switch ((MigrationType)ApplicationContext)
{ {
case MigrationType.Main:
MainDbUpgrade(); MainDbUpgrade();
} return;
else if ((MigrationType)ApplicationContext == MigrationType.Log) case MigrationType.Log:
{
LogDbUpgrade(); LogDbUpgrade();
} return;
else default:
{
LogDbUpgrade(); LogDbUpgrade();
MainDbUpgrade(); MainDbUpgrade();
return;
} }
} }

View File

@ -1,9 +1,4 @@
using System; namespace NzbDrone.Core.Datastore
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Datastore
{ {
public enum MigrationType public enum MigrationType
{ {

View File

@ -1,6 +1,4 @@
using System.Data; using System.Diagnostics;
using System.Diagnostics;
using Marr.Data;
namespace NzbDrone.Core.Datastore namespace NzbDrone.Core.Datastore
{ {

View File

@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Datastore namespace NzbDrone.Core.Datastore
{ {

View File

@ -1,10 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection;
using System.Text;
namespace NzbDrone.Core.Datastore namespace NzbDrone.Core.Datastore
{ {

View File

@ -1,8 +1,6 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using Marr.Data; using Marr.Data;
using Marr.Data.Mapping; using Marr.Data.Mapping;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;

View File

@ -0,0 +1,8 @@
using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.Instrumentation.Commands
{
public class TrimLogCommand : ICommand
{
}
}

View File

@ -1,6 +1,4 @@
using System; using System;
using System.Data;
using System.Linq;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
@ -20,8 +18,8 @@ public LogRepository(IDatabase database, IMessageAggregator messageAggregator)
public void Trim() public void Trim()
{ {
var oldIds = Query.Where(c => c.Time < DateTime.UtcNow.AddDays(-30).Date).Select(c => c.Id); var trimDate = DateTime.UtcNow.AddDays(-15).Date;
DeleteMany(oldIds); Delete(c => c.Time <= trimDate);
} }
} }
} }

View File

@ -1,16 +1,15 @@
using System.Linq; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Instrumentation.Commands;
namespace NzbDrone.Core.Instrumentation namespace NzbDrone.Core.Instrumentation
{ {
public interface ILogService public interface ILogService
{ {
void DeleteAll();
void Trim();
PagingSpec<Log> Paged(PagingSpec<Log> pagingSpec); PagingSpec<Log> Paged(PagingSpec<Log> pagingSpec);
} }
public class LogService : ILogService public class LogService : ILogService, IExecute<TrimLogCommand>
{ {
private readonly ILogRepository _logRepository; private readonly ILogRepository _logRepository;
@ -19,19 +18,14 @@ public LogService(ILogRepository logRepository)
_logRepository = logRepository; _logRepository = logRepository;
} }
public void DeleteAll()
{
_logRepository.Purge();
}
public void Trim()
{
_logRepository.Trim();
}
public PagingSpec<Log> Paged(PagingSpec<Log> pagingSpec) public PagingSpec<Log> Paged(PagingSpec<Log> pagingSpec)
{ {
return _logRepository.GetPaged(pagingSpec); return _logRepository.GetPaged(pagingSpec);
} }
public void Execute(TrimLogCommand message)
{
_logRepository.Trim();
}
} }
} }

View File

@ -4,6 +4,7 @@
using NLog; using NLog;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Instrumentation.Commands;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
@ -42,7 +43,8 @@ public void Handle(ApplicationStartedEvent message)
new ScheduledTask{ Interval = 12*60, TypeName = typeof(UpdateXemMappings).FullName}, new ScheduledTask{ Interval = 12*60, TypeName = typeof(UpdateXemMappings).FullName},
new ScheduledTask{ Interval = 6*60, TypeName = typeof(RefreshSeriesCommand).FullName}, new ScheduledTask{ Interval = 6*60, TypeName = typeof(RefreshSeriesCommand).FullName},
new ScheduledTask{ Interval = 1, TypeName = typeof(DownloadedEpisodesScanCommand).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(); var currentTasks = _scheduledTaskRepository.All();

View File

@ -204,14 +204,13 @@
<Compile Include="Datastore\Converters\EnumIntConverter.cs" /> <Compile Include="Datastore\Converters\EnumIntConverter.cs" />
<Compile Include="Datastore\Events\ModelEvent.cs" /> <Compile Include="Datastore\Events\ModelEvent.cs" />
<Compile Include="Datastore\IEmbeddedDocument.cs" /> <Compile Include="Datastore\IEmbeddedDocument.cs" />
<Compile Include="Datastore\IReadModels.cs" />
<Compile Include="Datastore\IWriteModels.cs" />
<Compile Include="Datastore\LazyList.cs" /> <Compile Include="Datastore\LazyList.cs" />
<Compile Include="Datastore\MappingExtensions.cs" /> <Compile Include="Datastore\MappingExtensions.cs" />
<Compile Include="Datastore\Migration\002_remove_tvrage_imdb_unique_constraint.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\003_remove_clean_title_from_scene_mapping.cs" />
<Compile Include="Datastore\Migration\004_updated_history.cs" /> <Compile Include="Datastore\Migration\004_updated_history.cs" />
<Compile Include="Datastore\Migration\005_added_eventtype_to_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\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationOptions.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationOptions.cs" />
@ -255,6 +254,7 @@
<Compile Include="Indexers\IndexerSettingUpdatedEvent.cs" /> <Compile Include="Indexers\IndexerSettingUpdatedEvent.cs" />
<Compile Include="Indexers\IndexerWithSetting.cs" /> <Compile Include="Indexers\IndexerWithSetting.cs" />
<Compile Include="Indexers\RssSyncCommand.cs" /> <Compile Include="Indexers\RssSyncCommand.cs" />
<Compile Include="Instrumentation\Commands\TrimLogCommand.cs" />
<Compile Include="Jobs\TaskManager.cs" /> <Compile Include="Jobs\TaskManager.cs" />
<Compile Include="Lifecycle\ApplicationShutdownRequested.cs" /> <Compile Include="Lifecycle\ApplicationShutdownRequested.cs" />
<Compile Include="MediaCover\CoverAlreadyExistsSpecification.cs" /> <Compile Include="MediaCover\CoverAlreadyExistsSpecification.cs" />

View File

@ -2,6 +2,7 @@
<FileVersion>1</FileVersion> <FileVersion>1</FileVersion>
<AutoEnableOnStartup>False</AutoEnableOnStartup> <AutoEnableOnStartup>False</AutoEnableOnStartup>
<AllowParallelTestExecution>true</AllowParallelTestExecution> <AllowParallelTestExecution>true</AllowParallelTestExecution>
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit> <FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio> <FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec> <FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>