Reverted the global app lock for the db #2750

pull/2922/head
tidusjar 6 years ago
parent 13a73020e5
commit 439dc395d0

@ -4,6 +4,7 @@ using Moq;
using Ombi.Core.Rule.Rules.Request;
using Ombi.Store.Entities.Requests;
using NUnit.Framework;
using Ombi.Core.Authentication;
using Ombi.Helpers;
namespace Ombi.Core.Tests.Rule.Request
@ -16,7 +17,7 @@ namespace Ombi.Core.Tests.Rule.Request
{
PrincipalMock = new Mock<IPrincipal>();
Rule = new AutoApproveRule(PrincipalMock.Object);
Rule = new AutoApproveRule(PrincipalMock.Object, null);
}

@ -16,7 +16,7 @@ namespace Ombi.Core.Tests.Rule.Request
{
PrincipalMock = new Mock<IPrincipal>();
Rule = new CanRequestRule(PrincipalMock.Object);
Rule = new CanRequestRule(PrincipalMock.Object, null);
}

@ -16,7 +16,7 @@ namespace Ombi.Core.Tests.Rule.Search
public void Setup()
{
ContextMock = new Mock<IEmbyContentRepository>();
Rule = new EmbyAvailabilityRule(ContextMock.Object);
Rule = new EmbyAvailabilityRule(ContextMock.Object, null);
}
private EmbyAvailabilityRule Rule { get; set; }

@ -158,7 +158,7 @@ namespace Ombi.Core.Authentication
if (!email.Equals(result.User?.Email))
{
user.Email = result.User?.Email;
await GlobalMutex.Lock(async () => await UpdateAsync(user));
await UpdateAsync(user);
}
return true;

@ -1,39 +0,0 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Nito.AsyncEx;
namespace Ombi.Helpers
{
public static class GlobalMutex
{
public static async Task<T> Lock<T>(Func<Task<T>> func)
{
const string mutexId = "Global\\OMBI";
using (var mutex = new Mutex(false, mutexId, out _))
{
var hasHandle = false;
try
{
try
{
hasHandle = mutex.WaitOne(5000, false);
if (hasHandle == false)
throw new TimeoutException("Timeout waiting for exclusive access");
}
catch (AbandonedMutexException)
{
hasHandle = true;
}
return await func();
}
finally
{
if (hasHandle)
mutex.ReleaseMutex();
}
}
}
}
}

@ -83,7 +83,7 @@ namespace Ombi.Store.Repository
protected async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await _ctx.SaveChangesAsync());
return await _ctx.SaveChangesAsync();
}

@ -68,7 +68,7 @@ namespace Ombi.Store.Repository
private async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
return await Db.SaveChangesAsync();
}
private bool _disposed;

@ -78,10 +78,5 @@ namespace Ombi.Store.Repository.Requests
{
await InternalSaveChanges();
}
private async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
}
}
}

@ -69,9 +69,5 @@ namespace Ombi.Store.Repository.Requests
{
await InternalSaveChanges();
}
private async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
}
}
}

@ -154,7 +154,7 @@ namespace Ombi.Store.Repository.Requests
private async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
return await Db.SaveChangesAsync();
}
}
}

@ -93,7 +93,7 @@ namespace Ombi.Store.Repository
private async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
return await Db.SaveChangesAsync();
}
private bool _disposed;

@ -29,7 +29,7 @@ namespace Ombi.Store.Repository
}
private async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
return await Db.SaveChangesAsync();
}
}
}

Loading…
Cancel
Save