mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
Log page now uses EF for faster runtime queries.
This commit is contained in:
parent
a984060533
commit
c6716f2425
49 changed files with 14898 additions and 555 deletions
22
NzbDrone.Core/Instrumentation/LogDbContext.cs
Normal file
22
NzbDrone.Core/Instrumentation/LogDbContext.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System.Data.Common;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using Ninject;
|
||||
|
||||
namespace NzbDrone.Core.Instrumentation
|
||||
{
|
||||
public class LogDbContext : DbContext
|
||||
{
|
||||
[Inject]
|
||||
public LogDbContext(DbConnection connection)
|
||||
: base(connection, false)
|
||||
{
|
||||
}
|
||||
|
||||
public LogDbContext()
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Log> Logs { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using PetaPoco;
|
||||
|
||||
|
@ -8,18 +9,20 @@ namespace NzbDrone.Core.Instrumentation
|
|||
public class LogProvider
|
||||
{
|
||||
private readonly IDatabase _database;
|
||||
private readonly LogDbContext _logDbContext;
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
||||
|
||||
public LogProvider(IDatabase database)
|
||||
public LogProvider(IDatabase database, LogDbContext logDbContext)
|
||||
{
|
||||
_database = database;
|
||||
_logDbContext = logDbContext;
|
||||
}
|
||||
|
||||
public IList<Log> GetAllLogs()
|
||||
public IQueryable<Log> GetAllLogs()
|
||||
{
|
||||
return _database.Fetch<Log>();
|
||||
return _logDbContext.Logs;
|
||||
}
|
||||
|
||||
public IList<Log> TopLogs(int count)
|
||||
|
@ -50,7 +53,7 @@ namespace NzbDrone.Core.Instrumentation
|
|||
public void Trim()
|
||||
{
|
||||
_database.Delete<Log>("WHERE Time < @0", DateTime.Now.AddDays(-30).Date);
|
||||
Logger.Info("Logs have been trimmed, events older than 30 days have been removed");
|
||||
Logger.Debug("Logs have been trimmed, events older than 30 days have been removed");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue