Handling race conditions on create if not exists of every repositories

This commit is contained in:
Zoe Roux 2020-06-11 23:04:22 +02:00
parent 57ade5470f
commit 7694bd97ae
8 changed files with 89 additions and 9 deletions

View File

@ -106,7 +106,17 @@ namespace Kyoo.Controllers
Episode old = await Get(obj.Slug);
if (old != null)
return old.ID;
return await Create(obj);
try
{
return await Create(obj);
}
catch (DuplicatedItemException)
{
old = await Get(obj.Slug);
if (old == null)
throw new SystemException("Unknown database state.");
return old.ID;
}
}
public async Task Edit(Episode edited, bool resetOld)

View File

@ -80,7 +80,17 @@ namespace Kyoo.Controllers
Genre old = await Get(obj.Slug);
if (old != null)
return old.ID;
return await Create(obj);
try
{
return await Create(obj);
}
catch (DuplicatedItemException)
{
old = await Get(obj.Slug);
if (old == null)
throw new SystemException("Unknown database state.");
return old.ID;
}
}
public async Task Edit(Genre edited, bool resetOld)

View File

@ -84,10 +84,20 @@ namespace Kyoo.Controllers
if (obj == null)
throw new ArgumentNullException(nameof(obj));
Library old = await Get(obj.Name);
Library old = await Get(obj.Slug);
if (old != null)
return old.ID;
return await Create(obj);
try
{
return await Create(obj);
}
catch (DuplicatedItemException)
{
old = await Get(obj.Slug);
if (old == null)
throw new SystemException("Unknown database state.");
return old.ID;
}
}
public async Task Edit(Library edited, bool resetOld)

View File

@ -86,7 +86,17 @@ namespace Kyoo.Controllers
People old = await Get(obj.Slug);
if (old != null)
return old.ID;
return await Create(obj);
try
{
return await Create(obj);
}
catch (DuplicatedItemException)
{
old = await Get(obj.Slug);
if (old == null)
throw new SystemException("Unknown database state.");
return old.ID;
}
}
public async Task Edit(People edited, bool resetOld)

View File

@ -80,7 +80,17 @@ namespace Kyoo.Controllers
ProviderID old = await Get(obj.Name);
if (old != null)
return old.ID;
return await Create(obj);
try
{
return await Create(obj);
}
catch (DuplicatedItemException)
{
old = await Get(obj.Name);
if (old == null)
throw new SystemException("Unknown database state.");
return old.ID;
}
}
public async Task Edit(ProviderID edited, bool resetOld)

View File

@ -99,7 +99,17 @@ namespace Kyoo.Controllers
Season old = await Get(obj.Slug);
if (old != null)
return old.ID;
return await Create(obj);
try
{
return await Create(obj);
}
catch (DuplicatedItemException)
{
old = await Get(obj.Slug);
if (old == null)
throw new SystemException("Unknown database state.");
return old.ID;
}
}
public async Task Edit(Season edited, bool resetOld)

View File

@ -103,7 +103,17 @@ namespace Kyoo.Controllers
Show old = await Get(obj.Slug);
if (old != null)
return old.ID;
return await Create(obj);
try
{
return await Create(obj);
}
catch (DuplicatedItemException)
{
old = await Get(obj.Slug);
if (old == null)
throw new SystemException("Unknown database state.");
return old.ID;
}
}
public async Task Edit(Show edited, bool resetOld)

View File

@ -79,7 +79,17 @@ namespace Kyoo.Controllers
Studio old = await Get(obj.Slug);
if (old != null)
return old.ID;
return await Create(obj);
try
{
return await Create(obj);
}
catch (DuplicatedItemException)
{
old = await Get(obj.Slug);
if (old == null)
throw new SystemException("Unknown database state.");
return old.ID;
}
}
public async Task Edit(Studio edited, bool resetOld)