Logging Change (#1941)

* Tweaked trace logging for foreign constraint issue.

Removed some locks where we werent touching important code that needed locking on.

* Reverted back some code
This commit is contained in:
Joe Milazzo 2023-04-22 14:43:41 -05:00 committed by GitHub
parent 201f8526f9
commit 3eb2874bbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -198,7 +198,14 @@ public class ProcessSeries : IProcessSeries
_logger.LogCritical(ex,
"[ScannerService] There was an issue writing to the database for series {SeriesName}",
series.Name);
_logger.LogTrace("[ScannerService] Full Series Dump: {@Series}", series);
_logger.LogTrace("[ScannerService] Series Metadata Dump: {@Series}", series.Metadata);
_logger.LogTrace("[ScannerService] People Dump: {@People}", _people
.Select(p =>
new {p.Id, p.Name, SeriesMetadataIds =
p.SeriesMetadatas?.Select(m => m.Id),
ChapterMetadataIds =
p.ChapterMetadatas?.Select(m => m.Id)
.ToList()}));
await _eventHub.SendMessageAsync(MessageFactory.Error,
MessageFactory.ErrorEvent($"There was an issue writing to the DB for Series {series}",
@ -316,7 +323,6 @@ public class ProcessSeries : IProcessSeries
if (!string.IsNullOrEmpty(firstChapter?.SeriesGroup) && library.ManageCollections)
{
_logger.LogDebug("Collection tag(s) found for {SeriesName}, updating collections", series.Name);
foreach (var collection in firstChapter.SeriesGroup.Split(','))
{
var normalizedName = Parser.Parser.Normalize(collection);
@ -330,19 +336,17 @@ public class ProcessSeries : IProcessSeries
}
}
lock (_genreLock)
if (!series.Metadata.GenresLocked)
{
var genres = chapters.SelectMany(c => c.Genres).ToList();
GenreHelper.KeepOnlySameGenreBetweenLists(series.Metadata.Genres.ToList(), genres, genre =>
{
if (series.Metadata.GenresLocked) return; // NOTE: Doesn't it make sense to do the locked skip outside this loop?
series.Metadata.Genres.Remove(genre);
});
}
// Handle People
lock (_peopleLock)
{
foreach (var chapter in chapters)
{
if (!series.Metadata.WriterLocked)
@ -479,12 +483,13 @@ public class ProcessSeries : IProcessSeries
case PersonRole.Translator:
if (!series.Metadata.TranslatorLocked) series.Metadata.People.Remove(person);
break;
case PersonRole.Other:
default:
series.Metadata.People.Remove(person);
break;
}
});
}
}
public void UpdateVolumes(Series series, IList<ParserInfo> parsedInfos, bool forceUpdate = false)
@ -727,18 +732,7 @@ public class ProcessSeries : IProcessSeries
void AddPerson(Person person)
{
// TODO: Temp have code inlined to help debug foreign key constraint issue
//PersonHelper.AddPersonIfNotExists(chapter.People, person);
if (string.IsNullOrEmpty(person.Name)) return;
var existingPerson = chapter.People.FirstOrDefault(p =>
p.NormalizedName == person.Name.ToNormalized() && p.Role == person.Role);
_logger.LogTrace("[PersonHelper] Attempting to add {@Person} to {FileName} with ChapterID {ChapterId}, adding if not null: {@ExistingPerson}",
person, chapter.Files.FirstOrDefault()?.FilePath, chapter.Id, existingPerson);
if (existingPerson == null)
{
chapter.People.Add(person);
}
PersonHelper.AddPersonIfNotExists(chapter.People, person);
}
void AddGenre(Genre genre, bool newTag)
@ -835,14 +829,13 @@ public class ProcessSeries : IProcessSeries
lock (_peopleLock)
{
var allPeopleTypeRole = _people.Where(p => p.Role == role).ToList();
_logger.LogTrace("[UpdatePeople] for {Role} and Names of {Names}", role, names);
_logger.LogTrace("[UpdatePeople] for {Role} found {@People}", role, allPeopleTypeRole.Select(p => new {p.Id, p.Name, SeriesMetadataIds = p.SeriesMetadatas?.Select(m => m.Id).ToList()}));
foreach (var name in names)
{
var normalizedName = name.ToNormalized();
var person = allPeopleTypeRole.FirstOrDefault(p =>
p.NormalizedName != null && p.NormalizedName.Equals(normalizedName));
_logger.LogTrace("[UpdatePeople] Checking if we can add {Name} for {Role}", names, role);
if (person == null)
{
@ -850,7 +843,7 @@ public class ProcessSeries : IProcessSeries
_logger.LogTrace("[UpdatePeople] for {Role} no one found, adding to _people", role);
_people.Add(person);
}
_logger.LogTrace("[UpdatePeople] For {Name}, found person with id: {Id}", role, person.Id);
action(person);
}
}