Fix Genre/Tag with spaces getting normalized (#3731)

This commit is contained in:
Joe Milazzo 2025-04-13 08:19:42 -06:00 committed by GitHub
parent 55966f0b2a
commit 33221fee2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 104 additions and 51 deletions

View file

@ -19,7 +19,12 @@ public static class GenreHelper
public static async Task UpdateChapterGenres(Chapter chapter, IEnumerable<string> genreNames, IUnitOfWork unitOfWork)
{
// Normalize genre names once and store them in a hash set for quick lookups
var normalizedGenresToAdd = new HashSet<string>(genreNames.Select(g => g.ToNormalized()));
var normalizedToOriginal = genreNames
.Select(g => new { Original = g, Normalized = g.ToNormalized() })
.GroupBy(x => x.Normalized)
.ToDictionary(g => g.Key, g => g.First().Original);
var normalizedGenresToAdd = new HashSet<string>(normalizedToOriginal.Keys);
// Remove genres that are no longer in the new list
var genresToRemove = chapter.Genres
@ -42,7 +47,7 @@ public static class GenreHelper
// Find missing genres that are not in the database
var missingGenres = normalizedGenresToAdd
.Where(nt => !existingGenreTitles.ContainsKey(nt))
.Select(title => new GenreBuilder(title).Build())
.Select(nt => new GenreBuilder(normalizedToOriginal[nt]).Build())
.ToList();
// Add missing genres to the database