added log trim command

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

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

View file

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