We are now only keeping the latest 1000 log records in the database. Delete everything else.

pull/332/head
tidusjar 9 years ago
parent 1c0e00e4ba
commit 5a8342eeb8

@ -25,6 +25,7 @@
// ************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
@ -51,14 +52,21 @@ namespace PlexRequests.Services.Jobs
private IRepository<LogEntity> Repo { get; }
private const int ItemsToDelete = 1000;
private void Cleanup()
{
try
{
var items = Repo.GetAll();
var orderedItems = items.Where(x => x.Date < DateTime.Now.AddDays(-2));
var ordered = items.OrderByDescending(x => x.Date).ToList();
var itemsToDelete = new List<LogEntity>();
if (ordered.Count > ItemsToDelete)
{
itemsToDelete = ordered.Skip(ItemsToDelete).ToList();
}
foreach (var o in orderedItems)
foreach (var o in itemsToDelete)
{
Repo.Delete(o);
}

@ -63,7 +63,7 @@ namespace PlexRequests.UI
var baseUrl = result.MapResult(
o => o.BaseUrl,
e => string.Empty);
var port = result.MapResult(
x => x.Port,
e => -1);

Loading…
Cancel
Save