Merge branch 'develop' into feature/v4

This commit is contained in:
Jamie Rees 2019-03-07 09:42:13 +00:00
commit cc5fb56e7b
13 changed files with 89 additions and 78 deletions

View file

@ -13,6 +13,7 @@ namespace Ombi.Store.Context
if (_created) return;
_created = true;
Database.SetCommandTimeout(60);
Database.Migrate();
}

View file

@ -18,6 +18,7 @@ namespace Ombi.Store.Context
if (_created) return;
_created = true;
Database.SetCommandTimeout(60);
Database.Migrate();
}
@ -107,6 +108,7 @@ namespace Ombi.Store.Context
var allAgents = Enum.GetValues(typeof(NotificationAgent)).Cast<NotificationAgent>().ToList();
var allTypes = Enum.GetValues(typeof(NotificationType)).Cast<NotificationType>().ToList();
var needToSave = false;
foreach (var agent in allAgents)
{
foreach (var notificationType in allTypes)
@ -116,6 +118,8 @@ namespace Ombi.Store.Context
// We already have this
continue;
}
needToSave = true;
NotificationTemplates notificationToAdd;
switch (notificationType)
{
@ -230,7 +234,11 @@ namespace Ombi.Store.Context
NotificationTemplates.Add(notificationToAdd);
}
}
SaveChanges();
if (needToSave)
{
SaveChanges();
}
}
}
}

View file

@ -14,6 +14,7 @@ namespace Ombi.Store.Context
if (_created) return;
_created = true;
Database.SetCommandTimeout(60);
Database.Migrate();
}
@ -63,13 +64,6 @@ namespace Ombi.Store.Context
});
SaveChanges();
}
SaveChanges();
}
~SettingsContext()
{
}
}
}

View file

@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Nito.AsyncEx" Version="5.0.0-pre-05" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="1.1.9" />
</ItemGroup>
<ItemGroup>

View file

@ -5,6 +5,7 @@ using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using Nito.AsyncEx;
using Ombi.Store.Context;
using Ombi.Store.Entities;
@ -19,6 +20,7 @@ namespace Ombi.Store.Repository
}
public DbSet<T> _db { get; }
private readonly U _ctx;
private readonly AsyncLock _mutex = new AsyncLock();
public async Task<T> Find(object key)
{
@ -40,32 +42,32 @@ namespace Ombi.Store.Repository
_db.AddRange(content);
if (save)
{
await _ctx.SaveChangesAsync();
await InternalSaveChanges();
}
}
public async Task<T> Add(T content)
{
await _db.AddAsync(content);
await _ctx.SaveChangesAsync();
await InternalSaveChanges();
return content;
}
public async Task Delete(T request)
{
_db.Remove(request);
await _ctx.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task DeleteRange(IEnumerable<T> req)
{
_db.RemoveRange(req);
await _ctx.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task<int> SaveChangesAsync()
{
return await _ctx.SaveChangesAsync();
return await InternalSaveChanges();
}
public IIncludableQueryable<TEntity, TProperty> Include<TEntity, TProperty>(
@ -80,6 +82,14 @@ namespace Ombi.Store.Repository
await _ctx.Database.ExecuteSqlCommandAsync(sql);
}
private async Task<int> InternalSaveChanges()
{
using (await _mutex.LockAsync())
{
return await _ctx.SaveChangesAsync();
}
}
private bool _disposed;
// Protected implementation of Dispose pattern.