mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-13 00:32:57 -07:00
Added a lock on the database commit level to see if I can improve locked db's
This commit is contained in:
parent
a039de24b0
commit
3592781e94
2 changed files with 16 additions and 5 deletions
|
@ -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 SaveChangesAsync();
|
||||
await InternalSaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<T> 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<T> req)
|
||||
{
|
||||
_db.RemoveRange(req);
|
||||
await SaveChangesAsync();
|
||||
await InternalSaveChanges();
|
||||
}
|
||||
|
||||
public async Task<int> SaveChangesAsync()
|
||||
{
|
||||
return await _ctx.SaveChangesAsync();
|
||||
return await InternalSaveChanges();
|
||||
}
|
||||
|
||||
public IIncludableQueryable<TEntity, TProperty> Include<TEntity, TProperty>(
|
||||
|
@ -79,6 +81,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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue