mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 01:02:57 -07:00
Made use of the global mutex, this should now hopefully work #2750
This commit is contained in:
parent
1322076aa6
commit
947c0e74cb
3 changed files with 11 additions and 14 deletions
|
@ -1,15 +1,16 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Nito.AsyncEx;
|
||||||
|
|
||||||
namespace Ombi.Helpers
|
namespace Ombi.Helpers
|
||||||
{
|
{
|
||||||
public static class GlobalMutex
|
public static class GlobalMutex
|
||||||
{
|
{
|
||||||
public static T Lock<T>(Func<T> func)
|
public static async Task<T> Lock<T>(Func<Task<T>> func)
|
||||||
{
|
{
|
||||||
const string mutexId = "Global\\OMBI";
|
const string mutexId = "Global\\OMBI";
|
||||||
|
using (var mutex = new Mutex(false, mutexId, out _))
|
||||||
using (var mutex = new Mutex(false, mutexId, out __))
|
|
||||||
{
|
{
|
||||||
var hasHandle = false;
|
var hasHandle = false;
|
||||||
try
|
try
|
||||||
|
@ -25,7 +26,7 @@ namespace Ombi.Helpers
|
||||||
hasHandle = true;
|
hasHandle = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return func();
|
return await func();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,7 @@ using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Query;
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
using Nito.AsyncEx;
|
using Ombi.Helpers;
|
||||||
using Ombi.Store.Context;
|
using Ombi.Store.Context;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ namespace Ombi.Store.Repository
|
||||||
}
|
}
|
||||||
public DbSet<T> _db { get; }
|
public DbSet<T> _db { get; }
|
||||||
private readonly U _ctx;
|
private readonly U _ctx;
|
||||||
private readonly AsyncLock _mutex = new AsyncLock();
|
|
||||||
|
|
||||||
public async Task<T> Find(object key)
|
public async Task<T> Find(object key)
|
||||||
{
|
{
|
||||||
|
@ -32,7 +31,7 @@ namespace Ombi.Store.Repository
|
||||||
return _db.AsQueryable();
|
return _db.AsQueryable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<T> FirstOrDefaultAsync(Expression<Func<T,bool>> predicate)
|
public async Task<T> FirstOrDefaultAsync(Expression<Func<T, bool>> predicate)
|
||||||
{
|
{
|
||||||
return await _db.FirstOrDefaultAsync(predicate);
|
return await _db.FirstOrDefaultAsync(predicate);
|
||||||
}
|
}
|
||||||
|
@ -84,10 +83,7 @@ namespace Ombi.Store.Repository
|
||||||
|
|
||||||
private async Task<int> InternalSaveChanges()
|
private async Task<int> InternalSaveChanges()
|
||||||
{
|
{
|
||||||
using (await _mutex.LockAsync())
|
return await GlobalMutex.Lock(async () => await _ctx.SaveChangesAsync());
|
||||||
{
|
|
||||||
return await _ctx.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ namespace Ombi.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
user.LastLoggedIn = DateTime.UtcNow;
|
user.LastLoggedIn = DateTime.UtcNow;
|
||||||
await _userManager.UpdateAsync(user);
|
await GlobalMutex.Lock(async () => await _userManager.UpdateAsync(user)).ConfigureAwait(false);
|
||||||
|
|
||||||
return new JsonResult(new
|
return new JsonResult(new
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue