diff --git a/src/Ombi.Store/Ombi.Store.csproj b/src/Ombi.Store/Ombi.Store.csproj
index 31c69c8d8..8dfcc1c28 100644
--- a/src/Ombi.Store/Ombi.Store.csproj
+++ b/src/Ombi.Store/Ombi.Store.csproj
@@ -15,6 +15,7 @@
+
diff --git a/src/Ombi.Store/Repository/BaseRepository.cs b/src/Ombi.Store/Repository/BaseRepository.cs
index efd277f43..21dd2dac5 100644
--- a/src/Ombi.Store/Repository/BaseRepository.cs
+++ b/src/Ombi.Store/Repository/BaseRepository.cs
@@ -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 _db { get; }
private readonly U _ctx;
+ private readonly AsyncLock _mutex = new AsyncLock();
public async Task Find(object key)
{
@@ -40,32 +42,32 @@ namespace Ombi.Store.Repository
_db.AddRange(content);
if (save)
{
- await SaveChangesAsync();
+ await InternalSaveChanges();
}
}
public async Task Add(T content)
{
await _db.AddAsync(content);
- await SaveChangesAsync();
+ await InternalSaveChanges();
return content;
}
public async Task Delete(T request)
{
_db.Remove(request);
- await SaveChangesAsync();
+ await InternalSaveChanges();
}
public async Task DeleteRange(IEnumerable req)
{
_db.RemoveRange(req);
- await SaveChangesAsync();
+ await InternalSaveChanges();
}
public async Task SaveChangesAsync()
{
- return await _ctx.SaveChangesAsync();
+ return await InternalSaveChanges();
}
public IIncludableQueryable Include(
@@ -79,6 +81,14 @@ namespace Ombi.Store.Repository
{
await _ctx.Database.ExecuteSqlCommandAsync(sql);
}
+
+ private async Task InternalSaveChanges()
+ {
+ using (await _mutex.LockAsync())
+ {
+ return await _ctx.SaveChangesAsync();
+ }
+ }
private bool _disposed;