Some memory management improvements

This commit is contained in:
tidusjar 2018-01-08 20:02:56 +00:00
commit 6ac9da8bed
30 changed files with 362 additions and 100 deletions

View file

@ -18,7 +18,6 @@ namespace Ombi.Store.Context
_created = true;
Database.Migrate();
}
public DbSet<NotificationTemplates> NotificationTemplates { get; set; }

View file

@ -25,6 +25,7 @@
// ************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -109,5 +110,24 @@ namespace Ombi.Store.Repository
Db.EmbyEpisode.AddRange(content);
await Db.SaveChangesAsync();
}
private bool _disposed;
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;
if (disposing)
{
Db?.Dispose();
}
_disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}

View file

@ -1,11 +1,12 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Ombi.Store.Entities;
namespace Ombi.Store.Repository
{
public interface IEmbyContentRepository
public interface IEmbyContentRepository : IDisposable
{
Task<EmbyContent> Add(EmbyContent content);
Task AddRange(IEnumerable<EmbyContent> content);

View file

@ -8,7 +8,7 @@ using Ombi.Store.Entities;
namespace Ombi.Store.Repository
{
public interface IRepository<T> where T : Entity
public interface IRepository<T> : IDisposable where T : Entity
{
Task<T> Find(object key);
IQueryable<T> GetAll();

View file

@ -1,10 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Ombi.Store.Entities;
namespace Ombi.Store.Repository
{
public interface ISettingsRepository
public interface ISettingsRepository : IDisposable
{
/// <summary>
/// Inserts the specified entity.

View file

@ -71,5 +71,27 @@ namespace Ombi.Store.Repository
{
return source.Include(navigationPropertyPath);
}
private bool _disposed;
// Protected implementation of Dispose pattern.
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;
if (disposing)
{
_ctx?.Dispose();
}
_disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}

View file

@ -89,5 +89,24 @@ namespace Ombi.Store.Repository
{
return $"{entity}Json";
}
private bool _disposed;
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;
if (disposing)
{
Db?.Dispose();
}
_disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}