Bug fix #173 : error when importing the same book from multiple accounts during the same import
This commit is contained in:
parent
41a4055cd9
commit
b260554a2a
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Version>6.5.5.1</Version>
|
<Version>6.5.6.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -120,17 +120,36 @@ namespace DtoImporterService
|
|||||||
|
|
||||||
var category = DbContext.Categories.Local.SingleOrDefault(c => c.AudibleCategoryId == lastCategory);
|
var category = DbContext.Categories.Local.SingleOrDefault(c => c.AudibleCategoryId == lastCategory);
|
||||||
|
|
||||||
var book = DbContext.Books.Add(new Book(
|
Book book;
|
||||||
new AudibleProductId(item.ProductId),
|
try
|
||||||
item.TitleWithSubtitle,
|
{
|
||||||
item.Description,
|
book = DbContext.Books.Add(new Book(
|
||||||
item.LengthInMinutes,
|
new AudibleProductId(item.ProductId),
|
||||||
contentType,
|
item.TitleWithSubtitle,
|
||||||
authors,
|
item.Description,
|
||||||
narrators,
|
item.LengthInMinutes,
|
||||||
category,
|
contentType,
|
||||||
importItem.LocaleName)
|
authors,
|
||||||
).Entity;
|
narrators,
|
||||||
|
category,
|
||||||
|
importItem.LocaleName)
|
||||||
|
).Entity;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Error(ex, "Error adding book. {@DebugInfo}", new {
|
||||||
|
item.ProductId,
|
||||||
|
item.TitleWithSubtitle,
|
||||||
|
item.Description,
|
||||||
|
item.LengthInMinutes,
|
||||||
|
contentType,
|
||||||
|
QtyAuthors = authors?.Count,
|
||||||
|
QtyNarrators = narrators?.Count,
|
||||||
|
Category = category?.Name,
|
||||||
|
importItem.LocaleName
|
||||||
|
});
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
var publisherName = item.Publisher;
|
var publisherName = item.Publisher;
|
||||||
if (!string.IsNullOrWhiteSpace(publisherName))
|
if (!string.IsNullOrWhiteSpace(publisherName))
|
||||||
|
|||||||
@ -73,7 +73,15 @@ namespace DtoImporterService
|
|||||||
var category = DbContext.Categories.Local.FirstOrDefault(c => c.AudibleCategoryId == id);
|
var category = DbContext.Categories.Local.FirstOrDefault(c => c.AudibleCategoryId == id);
|
||||||
if (category is null)
|
if (category is null)
|
||||||
{
|
{
|
||||||
category = DbContext.Categories.Add(new Category(new AudibleCategoryId(id), name)).Entity;
|
try
|
||||||
|
{
|
||||||
|
category = DbContext.Categories.Add(new Category(new AudibleCategoryId(id), name)).Entity;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Error(ex, "Error adding category. {@DebugInfo}", new { id, name });
|
||||||
|
throw;
|
||||||
|
}
|
||||||
qtyNew++;
|
qtyNew++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,16 @@ namespace DtoImporterService
|
|||||||
foreach (var name in newPeople)
|
foreach (var name in newPeople)
|
||||||
{
|
{
|
||||||
var p = groupby.Single(g => g.Name == name).People.First();
|
var p = groupby.Single(g => g.Name == name).People.First();
|
||||||
DbContext.Contributors.Add(new Contributor(p.Name, p.Asin));
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DbContext.Contributors.Add(new Contributor(p.Name, p.Asin));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Error(ex, "Error adding person. {@DebugInfo}", new { p?.Name, p?.Asin });
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPeople.Count;
|
return newPeople.Count;
|
||||||
@ -99,7 +108,17 @@ namespace DtoImporterService
|
|||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
foreach (var pub in newPublishers)
|
foreach (var pub in newPublishers)
|
||||||
DbContext.Contributors.Add(new Contributor(pub));
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DbContext.Contributors.Add(new Contributor(pub));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Error(ex, "Error adding publisher. {@DebugInfo}", new { pub });
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return newPublishers.Count;
|
return newPublishers.Count;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,18 +35,38 @@ namespace DtoImporterService
|
|||||||
// CURRENT SOLUTION: don't re-insert
|
// CURRENT SOLUTION: don't re-insert
|
||||||
|
|
||||||
var currentLibraryProductIds = DbContext.LibraryBooks.Select(l => l.Book.AudibleProductId).ToList();
|
var currentLibraryProductIds = DbContext.LibraryBooks.Select(l => l.Book.AudibleProductId).ToList();
|
||||||
var newItems = importItems.Where(dto => !currentLibraryProductIds.Contains(dto.DtoItem.ProductId)).ToList();
|
var newItems = importItems
|
||||||
|
.Where(dto => !currentLibraryProductIds
|
||||||
|
.Contains(dto.DtoItem.ProductId))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
foreach (var newItem in newItems)
|
// if 2 accounts try to import the same book in the same transaction: error since we're only tracking and pulling by asin.
|
||||||
|
// just use the first
|
||||||
|
var groupby = newItems.GroupBy(
|
||||||
|
i => i.DtoItem.ProductId,
|
||||||
|
i => i,
|
||||||
|
(key, g) => new { ProductId = key, ImportItems = g.ToList() }
|
||||||
|
)
|
||||||
|
.ToList();
|
||||||
|
foreach (var gb in groupby)
|
||||||
{
|
{
|
||||||
|
var newItem = gb.ImportItems.First();
|
||||||
|
|
||||||
var libraryBook = new LibraryBook(
|
var libraryBook = new LibraryBook(
|
||||||
DbContext.Books.Local.Single(b => b.AudibleProductId == newItem.DtoItem.ProductId),
|
DbContext.Books.Local.Single(b => b.AudibleProductId == newItem.DtoItem.ProductId),
|
||||||
newItem.DtoItem.DateAdded,
|
newItem.DtoItem.DateAdded,
|
||||||
newItem.AccountId);
|
newItem.AccountId);
|
||||||
DbContext.LibraryBooks.Add(libraryBook);
|
try
|
||||||
|
{
|
||||||
|
DbContext.LibraryBooks.Add(libraryBook);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Error(ex, "Error adding library book. {@DebugInfo}", new { libraryBook.Book, libraryBook.Account });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var qtyNew = newItems.Count;
|
var qtyNew = groupby.Count;
|
||||||
return qtyNew;
|
return qtyNew;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,7 +51,15 @@ namespace DtoImporterService
|
|||||||
var series = DbContext.Series.Local.FirstOrDefault(c => c.AudibleSeriesId == s.SeriesId);
|
var series = DbContext.Series.Local.FirstOrDefault(c => c.AudibleSeriesId == s.SeriesId);
|
||||||
if (series is null)
|
if (series is null)
|
||||||
{
|
{
|
||||||
series = DbContext.Series.Add(new DataLayer.Series(new AudibleSeriesId(s.SeriesId))).Entity;
|
try
|
||||||
|
{
|
||||||
|
series = DbContext.Series.Add(new DataLayer.Series(new AudibleSeriesId(s.SeriesId))).Entity;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Error(ex, "Error adding series. {@DebugInfo}", new { s?.SeriesId });
|
||||||
|
throw;
|
||||||
|
}
|
||||||
qtyNew++;
|
qtyNew++;
|
||||||
}
|
}
|
||||||
series.UpdateName(s.SeriesName);
|
series.UpdateName(s.SeriesName);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user