Scanner Performance Improvements (#1774)

* Refactored the Genre code to be faster and used a dictonary to avoid some lookups. May fix the rare foreign constraint issue.

* Refactored tag to the same implementation as Genre. Ensure when grabbing tags from ComicInfo, we normalize and throw out duplicates.

* Removed an internal "external" field that was planned for Genres and Tags, but now with new plugin architecture, not needed.
This commit is contained in:
Joe Milazzo 2023-02-03 04:52:51 -08:00 committed by GitHub
parent 48aebfc3c2
commit 8a0a2f0961
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 1925 additions and 152 deletions

View file

@ -13,13 +13,13 @@ public class GenreHelperTests
{
var allGenres = new List<Genre>
{
DbFactory.Genre("Action", false),
DbFactory.Genre("action", false),
DbFactory.Genre("Sci-fi", false),
DbFactory.Genre("Action"),
DbFactory.Genre("action"),
DbFactory.Genre("Sci-fi"),
};
var genreAdded = new List<Genre>();
GenreHelper.UpdateGenre(allGenres, new[] {"Action", "Adventure"}, false, genre =>
GenreHelper.UpdateGenre(allGenres, new[] {"Action", "Adventure"}, genre =>
{
genreAdded.Add(genre);
});
@ -33,19 +33,20 @@ public class GenreHelperTests
{
var allGenres = new List<Genre>
{
DbFactory.Genre("Action", false),
DbFactory.Genre("action", false),
DbFactory.Genre("Sci-fi", false),
DbFactory.Genre("Action"),
DbFactory.Genre("action"),
DbFactory.Genre("Sci-fi"),
};
var genreAdded = new List<Genre>();
GenreHelper.UpdateGenre(allGenres, new[] {"Action", "Scifi"}, false, genre =>
GenreHelper.UpdateGenre(allGenres, new[] {"Action", "Scifi"}, genre =>
{
genreAdded.Add(genre);
});
Assert.Equal(3, allGenres.Count);
Assert.Equal(2, genreAdded.Count);
}
[Fact]
@ -53,49 +54,34 @@ public class GenreHelperTests
{
var existingGenres = new List<Genre>
{
DbFactory.Genre("Action", false),
DbFactory.Genre("action", false),
DbFactory.Genre("Sci-fi", false),
DbFactory.Genre("Action"),
DbFactory.Genre("action"),
DbFactory.Genre("Sci-fi"),
};
GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("Action", false));
GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("Action"));
Assert.Equal(3, existingGenres.Count);
GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("action", false));
GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("action"));
Assert.Equal(3, existingGenres.Count);
GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("Shonen", false));
GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("Shonen"));
Assert.Equal(4, existingGenres.Count);
}
[Fact]
public void AddGenre_ShouldNotAddSameNameAndExternal()
{
var existingGenres = new List<Genre>
{
DbFactory.Genre("Action", false),
DbFactory.Genre("action", false),
DbFactory.Genre("Sci-fi", false),
};
GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("Action", true));
Assert.Equal(3, existingGenres.Count);
}
[Fact]
public void KeepOnlySamePeopleBetweenLists()
{
var existingGenres = new List<Genre>
{
DbFactory.Genre("Action", false),
DbFactory.Genre("Sci-fi", false),
DbFactory.Genre("Action"),
DbFactory.Genre("Sci-fi"),
};
var peopleFromChapters = new List<Genre>
{
DbFactory.Genre("Action", false),
DbFactory.Genre("Action"),
};
var genreRemoved = new List<Genre>();
@ -113,8 +99,8 @@ public class GenreHelperTests
{
var existingGenres = new List<Genre>
{
DbFactory.Genre("Action", false),
DbFactory.Genre("Sci-fi", false),
DbFactory.Genre("Action"),
DbFactory.Genre("Sci-fi"),
};
var peopleFromChapters = new List<Genre>();

View file

@ -13,13 +13,13 @@ public class TagHelperTests
{
var allTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("action", false),
DbFactory.Tag("Sci-fi", false),
DbFactory.Tag("Action"),
DbFactory.Tag("action"),
DbFactory.Tag("Sci-fi"),
};
var tagAdded = new List<Tag>();
TagHelper.UpdateTag(allTags, new[] {"Action", "Adventure"}, false, (tag, added) =>
TagHelper.UpdateTag(allTags, new[] {"Action", "Adventure"}, (tag, added) =>
{
if (added)
{
@ -37,14 +37,14 @@ public class TagHelperTests
{
var allTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("action", false),
DbFactory.Tag("Sci-fi", false),
DbFactory.Tag("Action"),
DbFactory.Tag("action"),
DbFactory.Tag("Sci-fi"),
};
var tagAdded = new List<Tag>();
TagHelper.UpdateTag(allTags, new[] {"Action", "Scifi"}, false, (tag, added) =>
TagHelper.UpdateTag(allTags, new[] {"Action", "Scifi"}, (tag, added) =>
{
if (added)
{
@ -62,49 +62,34 @@ public class TagHelperTests
{
var existingTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("action", false),
DbFactory.Tag("Sci-fi", false),
DbFactory.Tag("Action"),
DbFactory.Tag("action"),
DbFactory.Tag("Sci-fi"),
};
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Action", false));
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Action"));
Assert.Equal(3, existingTags.Count);
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("action", false));
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("action"));
Assert.Equal(3, existingTags.Count);
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Shonen", false));
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Shonen"));
Assert.Equal(4, existingTags.Count);
}
[Fact]
public void AddTag_ShouldNotAddSameNameAndExternal()
{
var existingTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("action", false),
DbFactory.Tag("Sci-fi", false),
};
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Action", true));
Assert.Equal(3, existingTags.Count);
}
[Fact]
public void KeepOnlySamePeopleBetweenLists()
{
var existingTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("Sci-fi", false),
DbFactory.Tag("Action"),
DbFactory.Tag("Sci-fi"),
};
var peopleFromChapters = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("Action"),
};
var tagRemoved = new List<Tag>();
@ -122,8 +107,8 @@ public class TagHelperTests
{
var existingTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("Sci-fi", false),
DbFactory.Tag("Action"),
DbFactory.Tag("Sci-fi"),
};
var peopleFromChapters = new List<Tag>();