mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 15:56:05 -07:00
We are now only keeping the latest 1000 log records in the database. Delete everything else.
This commit is contained in:
parent
1c0e00e4ba
commit
5a8342eeb8
2 changed files with 11 additions and 3 deletions
|
@ -25,6 +25,7 @@
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
@ -51,14 +52,21 @@ namespace PlexRequests.Services.Jobs
|
||||||
|
|
||||||
private IRepository<LogEntity> Repo { get; }
|
private IRepository<LogEntity> Repo { get; }
|
||||||
|
|
||||||
|
private const int ItemsToDelete = 1000;
|
||||||
|
|
||||||
private void Cleanup()
|
private void Cleanup()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var items = Repo.GetAll();
|
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);
|
Repo.Delete(o);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue