Collection Rework (#2830)
This commit is contained in:
parent
0dacc061f1
commit
deaaccb96a
93 changed files with 5413 additions and 1120 deletions
|
@ -467,14 +467,13 @@ public class ParseScannedFiles
|
|||
}
|
||||
|
||||
|
||||
chapters = infos
|
||||
.OrderByNatural(info => info.Chapters)
|
||||
.ToList();
|
||||
|
||||
|
||||
// If everything is a special but we don't have any SpecialIndex, then order naturally and use 0, 1, 2
|
||||
if (specialTreatment)
|
||||
{
|
||||
chapters = infos
|
||||
.OrderByNatural(info => Parser.Parser.RemoveExtensionIfSupported(info.Filename)!)
|
||||
.ToList();
|
||||
|
||||
foreach (var chapter in chapters)
|
||||
{
|
||||
chapter.IssueOrder = counter;
|
||||
|
@ -483,6 +482,9 @@ public class ParseScannedFiles
|
|||
return;
|
||||
}
|
||||
|
||||
chapters = infos
|
||||
.OrderByNatural(info => info.Chapters)
|
||||
.ToList();
|
||||
|
||||
counter = 0f;
|
||||
var prevIssue = string.Empty;
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using API.Data;
|
||||
using API.Data.Metadata;
|
||||
using API.Data.Repositories;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Extensions;
|
||||
|
@ -371,12 +372,26 @@ public class ProcessSeries : IProcessSeries
|
|||
|
||||
if (!string.IsNullOrEmpty(firstChapter?.SeriesGroup) && library.ManageCollections)
|
||||
{
|
||||
// Get the default admin to associate these tags to
|
||||
var defaultAdmin = await _unitOfWork.UserRepository.GetDefaultAdminUser(AppUserIncludes.Collections);
|
||||
if (defaultAdmin == null) return;
|
||||
|
||||
_logger.LogDebug("Collection tag(s) found for {SeriesName}, updating collections", series.Name);
|
||||
foreach (var collection in firstChapter.SeriesGroup.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
var t = await _tagManagerService.GetCollectionTag(collection);
|
||||
if (t == null) continue;
|
||||
_collectionTagService.AddTagToSeriesMetadata(t, series.Metadata);
|
||||
var t = await _tagManagerService.GetCollectionTag(collection, defaultAdmin);
|
||||
if (t.Item1 == null) continue;
|
||||
|
||||
var tag = t.Item1;
|
||||
|
||||
// Check if the Series is already on the tag
|
||||
if (tag.Items.Any(s => s.MatchesSeriesByName(series.NormalizedName, series.NormalizedLocalizedName)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
tag.Items.Add(series);
|
||||
await _unitOfWork.CollectionTagRepository.UpdateCollectionAgeRating(tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -28,7 +29,7 @@ public interface ITagManagerService
|
|||
Task<Genre?> GetGenre(string genre);
|
||||
Task<Tag?> GetTag(string tag);
|
||||
Task<Person?> GetPerson(string name, PersonRole role);
|
||||
Task<CollectionTag?> GetCollectionTag(string name);
|
||||
Task<Tuple<AppUserCollection?, bool>> GetCollectionTag(string? tag, AppUser userWithCollections);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -41,7 +42,7 @@ public class TagManagerService : ITagManagerService
|
|||
private Dictionary<string, Genre> _genres;
|
||||
private Dictionary<string, Tag> _tags;
|
||||
private Dictionary<string, Person> _people;
|
||||
private Dictionary<string, CollectionTag> _collectionTags;
|
||||
private Dictionary<string, AppUserCollection> _collectionTags;
|
||||
|
||||
private readonly SemaphoreSlim _genreSemaphore = new SemaphoreSlim(1, 1);
|
||||
private readonly SemaphoreSlim _tagSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
@ -57,10 +58,10 @@ public class TagManagerService : ITagManagerService
|
|||
|
||||
public void Reset()
|
||||
{
|
||||
_genres = new Dictionary<string, Genre>();
|
||||
_tags = new Dictionary<string, Tag>();
|
||||
_people = new Dictionary<string, Person>();
|
||||
_collectionTags = new Dictionary<string, CollectionTag>();
|
||||
_genres = [];
|
||||
_tags = [];
|
||||
_people = [];
|
||||
_collectionTags = [];
|
||||
}
|
||||
|
||||
public async Task Prime()
|
||||
|
@ -71,7 +72,8 @@ public class TagManagerService : ITagManagerService
|
|||
.GroupBy(GetPersonKey)
|
||||
.Select(g => g.First())
|
||||
.ToDictionary(GetPersonKey);
|
||||
_collectionTags = (await _unitOfWork.CollectionTagRepository.GetAllTagsAsync(CollectionTagIncludes.SeriesMetadata))
|
||||
var defaultAdmin = await _unitOfWork.UserRepository.GetDefaultAdminUser()!;
|
||||
_collectionTags = (await _unitOfWork.CollectionTagRepository.GetCollectionsForUserAsync(defaultAdmin.Id, CollectionIncludes.Series))
|
||||
.ToDictionary(t => t.NormalizedTitle);
|
||||
|
||||
}
|
||||
|
@ -183,28 +185,30 @@ public class TagManagerService : ITagManagerService
|
|||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<CollectionTag?> GetCollectionTag(string tag)
|
||||
public async Task<Tuple<AppUserCollection?, bool>> GetCollectionTag(string? tag, AppUser userWithCollections)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tag)) return null;
|
||||
if (string.IsNullOrEmpty(tag)) return Tuple.Create<AppUserCollection?, bool>(null, false);
|
||||
|
||||
await _collectionTagSemaphore.WaitAsync();
|
||||
AppUserCollection? result;
|
||||
try
|
||||
{
|
||||
if (_collectionTags.TryGetValue(tag.ToNormalized(), out var result))
|
||||
if (_collectionTags.TryGetValue(tag.ToNormalized(), out result))
|
||||
{
|
||||
return result;
|
||||
return Tuple.Create<AppUserCollection?, bool>(result, false);
|
||||
}
|
||||
|
||||
// We need to create a new Genre
|
||||
result = new CollectionTagBuilder(tag).Build();
|
||||
_unitOfWork.CollectionTagRepository.Add(result);
|
||||
result = new AppUserCollectionBuilder(tag).Build();
|
||||
userWithCollections.Collections.Add(result);
|
||||
_unitOfWork.UserRepository.Update(userWithCollections);
|
||||
await _unitOfWork.CommitAsync();
|
||||
_collectionTags.Add(result.NormalizedTitle, result);
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_collectionTagSemaphore.Release();
|
||||
}
|
||||
return Tuple.Create<AppUserCollection?, bool>(result, true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue