Release Shakeout Day 1 (#1591)

* Fixed an issue where reading list were not able to update their summary due to a duplicate title check.

* Misc code smell cleanup

* Updated .net dependencies and removed unneeded ones

* Fixed an issue where removing a series from want to read list page wouldn't update the page correctly

* Fixed age restriction not applied to Recommended page

* Ensure that Genres and Tags are age restricted gated

* Persons are now age gated as well

* When you choose a cover, the new cover will properly be selected and will focus on it, in the cases there are many other covers available.

* Fixed caching profiles

* Added in a special hook when deleting a library to clear all series Relations before we delete
This commit is contained in:
Joe Milazzo 2022-10-18 16:53:17 -07:00 committed by GitHub
parent 03bd2e9103
commit b802e1e1b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 404 additions and 153 deletions

View file

@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using API.Data.Misc;
using API.DTOs.Metadata;
using API.Entities;
using API.Extensions;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using Microsoft.EntityFrameworkCore;
@ -15,9 +17,9 @@ public interface IGenreRepository
void Remove(Genre genre);
Task<Genre> FindByNameAsync(string genreName);
Task<IList<Genre>> GetAllGenresAsync();
Task<IList<GenreTagDto>> GetAllGenreDtosAsync();
Task<IList<GenreTagDto>> GetAllGenreDtosAsync(int userId);
Task RemoveAllGenreNoLongerAssociated(bool removeExternal = false);
Task<IList<GenreTagDto>> GetAllGenreDtosForLibrariesAsync(IList<int> libraryIds);
Task<IList<GenreTagDto>> GetAllGenreDtosForLibrariesAsync(IList<int> libraryIds, int userId);
Task<int> GetCountAsync();
}
@ -63,10 +65,18 @@ public class GenreRepository : IGenreRepository
await _context.SaveChangesAsync();
}
public async Task<IList<GenreTagDto>> GetAllGenreDtosForLibrariesAsync(IList<int> libraryIds)
/// <summary>
/// Returns a set of Genre tags for a set of library Ids. UserId will restrict returned Genres based on user's age restriction.
/// </summary>
/// <param name="libraryIds"></param>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<IList<GenreTagDto>> GetAllGenreDtosForLibrariesAsync(IList<int> libraryIds, int userId)
{
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
return await _context.Series
.Where(s => libraryIds.Contains(s.LibraryId))
.RestrictAgainstAgeRestriction(userRating)
.SelectMany(s => s.Metadata.Genres)
.AsSplitQuery()
.Distinct()
@ -75,6 +85,7 @@ public class GenreRepository : IGenreRepository
.ToListAsync();
}
public async Task<int> GetCountAsync()
{
return await _context.Genre.CountAsync();
@ -85,9 +96,11 @@ public class GenreRepository : IGenreRepository
return await _context.Genre.ToListAsync();
}
public async Task<IList<GenreTagDto>> GetAllGenreDtosAsync()
public async Task<IList<GenreTagDto>> GetAllGenreDtosAsync(int userId)
{
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
return await _context.Genre
.RestrictAgainstAgeRestriction(ageRating)
.AsNoTracking()
.ProjectTo<GenreTagDto>(_mapper.ConfigurationProvider)
.ToListAsync();

View file

@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks;
using API.DTOs;
using API.Entities;
using API.Extensions;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using Microsoft.EntityFrameworkCore;
@ -14,8 +15,9 @@ public interface IPersonRepository
void Attach(Person person);
void Remove(Person person);
Task<IList<Person>> GetAllPeople();
Task<IList<PersonDto>> GetAllPersonDtosAsync(int userId);
Task RemoveAllPeopleNoLongerAssociated(bool removeExternal = false);
Task<IList<PersonDto>> GetAllPeopleDtosForLibrariesAsync(List<int> libraryIds);
Task<IList<PersonDto>> GetAllPeopleDtosForLibrariesAsync(List<int> libraryIds, int userId);
Task<int> GetCountAsync();
}
@ -40,14 +42,6 @@ public class PersonRepository : IPersonRepository
_context.Person.Remove(person);
}
public async Task<Person> FindByNameAsync(string name)
{
var normalizedName = Services.Tasks.Scanner.Parser.Parser.Normalize(name);
return await _context.Person
.Where(p => normalizedName.Equals(p.NormalizedName))
.SingleOrDefaultAsync();
}
public async Task RemoveAllPeopleNoLongerAssociated(bool removeExternal = false)
{
var peopleWithNoConnections = await _context.Person
@ -62,10 +56,12 @@ public class PersonRepository : IPersonRepository
await _context.SaveChangesAsync();
}
public async Task<IList<PersonDto>> GetAllPeopleDtosForLibrariesAsync(List<int> libraryIds)
public async Task<IList<PersonDto>> GetAllPeopleDtosForLibrariesAsync(List<int> libraryIds, int userId)
{
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
return await _context.Series
.Where(s => libraryIds.Contains(s.LibraryId))
.RestrictAgainstAgeRestriction(ageRating)
.SelectMany(s => s.Metadata.People)
.Distinct()
.OrderBy(p => p.Name)
@ -87,4 +83,14 @@ public class PersonRepository : IPersonRepository
.OrderBy(p => p.Name)
.ToListAsync();
}
public async Task<IList<PersonDto>> GetAllPersonDtosAsync(int userId)
{
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
return await _context.Person
.OrderBy(p => p.Name)
.RestrictAgainstAgeRestriction(ageRating)
.ProjectTo<PersonDto>(_mapper.ConfigurationProvider)
.ToListAsync();
}
}

View file

@ -291,7 +291,7 @@ public class SeriesRepository : ISeriesRepository
const int maxRecords = 15;
var result = new SearchResultGroupDto();
var searchQueryNormalized = Services.Tasks.Scanner.Parser.Parser.Normalize(searchQuery);
var userRating = await GetUserAgeRestriction(userId);
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
var seriesIds = _context.Series
.Where(s => libraryIds.Contains(s.LibraryId))
@ -723,7 +723,7 @@ public class SeriesRepository : ISeriesRepository
private async Task<IQueryable<Series>> CreateFilteredSearchQueryable(int userId, int libraryId, FilterDto filter)
{
var userLibraries = await GetUserLibraries(libraryId, userId);
var userRating = await GetUserAgeRestriction(userId);
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
var formats = ExtractFilters(libraryId, userId, filter, ref userLibraries,
out var allPeopleIds, out var hasPeopleFilter, out var hasGenresFilter,
@ -1027,59 +1027,46 @@ public class SeriesRepository : ISeriesRepository
public async Task<IEnumerable<GroupedSeriesDto>> GetRecentlyUpdatedSeries(int userId, int pageSize = 30)
{
var seriesMap = new Dictionary<string, GroupedSeriesDto>();
var index = 0;
var userRating = await GetUserAgeRestriction(userId);
var index = 0;
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
var items = (await GetRecentlyAddedChaptersQuery(userId));
if (userRating.AgeRating != AgeRating.NotApplicable)
var items = (await GetRecentlyAddedChaptersQuery(userId));
if (userRating.AgeRating != AgeRating.NotApplicable)
{
items = items.RestrictAgainstAgeRestriction(userRating);
}
foreach (var item in items)
{
if (seriesMap.Keys.Count == pageSize) break;
if (seriesMap.ContainsKey(item.SeriesName))
{
items = items.RestrictAgainstAgeRestriction(userRating);
seriesMap[item.SeriesName].Count += 1;
}
foreach (var item in items)
else
{
if (seriesMap.Keys.Count == pageSize) break;
if (seriesMap.ContainsKey(item.SeriesName))
seriesMap[item.SeriesName] = new GroupedSeriesDto()
{
seriesMap[item.SeriesName].Count += 1;
}
else
{
seriesMap[item.SeriesName] = new GroupedSeriesDto()
{
LibraryId = item.LibraryId,
LibraryType = item.LibraryType,
SeriesId = item.SeriesId,
SeriesName = item.SeriesName,
Created = item.Created,
Id = index,
Format = item.Format,
Count = 1,
};
index += 1;
}
LibraryId = item.LibraryId,
LibraryType = item.LibraryType,
SeriesId = item.SeriesId,
SeriesName = item.SeriesName,
Created = item.Created,
Id = index,
Format = item.Format,
Count = 1,
};
index += 1;
}
}
return seriesMap.Values.AsEnumerable();
}
private async Task<AgeRestriction> GetUserAgeRestriction(int userId)
{
return await _context.AppUser
.AsNoTracking()
.Where(u => u.Id == userId)
.Select(u =>
new AgeRestriction(){
AgeRating = u.AgeRestriction,
IncludeUnknowns = u.AgeRestrictionIncludeUnknowns
})
.SingleAsync();
return seriesMap.Values.AsEnumerable();
}
public async Task<IEnumerable<SeriesDto>> GetSeriesForRelationKind(int userId, int seriesId, RelationKind kind)
{
var libraryIds = GetLibraryIdsForUser(userId);
var userRating = await GetUserAgeRestriction(userId);
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
var usersSeriesIds = _context.Series
.Where(s => libraryIds.Contains(s.LibraryId))
@ -1108,9 +1095,14 @@ public class SeriesRepository : ISeriesRepository
var libraryIds = GetLibraryIdsForUser(userId, libraryId);
var usersSeriesIds = GetSeriesIdsForLibraryIds(libraryIds);
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
// Because this can be called from an API, we need to provide an additional check if the genre has anything the
// user with age restrictions can access
var query = _context.Series
.Where(s => s.Metadata.Genres.Select(g => g.Id).Contains(genreId))
.Where(s => usersSeriesIds.Contains(s.Id))
.RestrictAgainstAgeRestriction(userRating)
.AsSplitQuery()
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider);
@ -1147,7 +1139,7 @@ public class SeriesRepository : ISeriesRepository
public async Task<SeriesDto> GetSeriesForMangaFile(int mangaFileId, int userId)
{
var libraryIds = GetLibraryIdsForUser(userId);
var userRating = await GetUserAgeRestriction(userId);
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
return await _context.MangaFile
.Where(m => m.Id == mangaFileId)
@ -1164,7 +1156,7 @@ public class SeriesRepository : ISeriesRepository
public async Task<SeriesDto> GetSeriesForChapter(int chapterId, int userId)
{
var libraryIds = GetLibraryIdsForUser(userId);
var userRating = await GetUserAgeRestriction(userId);
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
return await _context.Chapter
.Where(m => m.Id == chapterId)
.AsSplitQuery()
@ -1321,9 +1313,11 @@ public class SeriesRepository : ISeriesRepository
.Where(s => usersSeriesIds.Contains(s.SeriesId) && s.Rating > 4)
.Select(p => p.SeriesId)
.Distinct();
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
var query = _context.Series
.Where(s => distinctSeriesIdsWithHighRating.Contains(s.Id))
.RestrictAgainstAgeRestriction(userRating)
.AsSplitQuery()
.OrderByDescending(s => _context.AppUserRating.Where(r => r.SeriesId == s.Id).Select(r => r.Rating).Average())
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider);
@ -1340,6 +1334,7 @@ public class SeriesRepository : ISeriesRepository
.Where(s => usersSeriesIds.Contains(s.SeriesId))
.Select(p => p.SeriesId)
.Distinct();
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
var query = _context.Series
@ -1349,6 +1344,7 @@ public class SeriesRepository : ISeriesRepository
&& !distinctSeriesIdsWithProgress.Contains(s.Id) &&
usersSeriesIds.Contains(s.Id))
.Where(s => s.Metadata.PublicationStatus != PublicationStatus.OnGoing)
.RestrictAgainstAgeRestriction(userRating)
.AsSplitQuery()
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider);
@ -1365,6 +1361,8 @@ public class SeriesRepository : ISeriesRepository
.Select(p => p.SeriesId)
.Distinct();
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
var query = _context.Series
.Where(s => (
@ -1373,6 +1371,7 @@ public class SeriesRepository : ISeriesRepository
&& !distinctSeriesIdsWithProgress.Contains(s.Id) &&
usersSeriesIds.Contains(s.Id))
.Where(s => s.Metadata.PublicationStatus == PublicationStatus.OnGoing)
.RestrictAgainstAgeRestriction(userRating)
.AsSplitQuery()
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider);
@ -1406,7 +1405,7 @@ public class SeriesRepository : ISeriesRepository
{
var libraryIds = GetLibraryIdsForUser(userId);
var usersSeriesIds = GetSeriesIdsForLibraryIds(libraryIds);
var userRating = await GetUserAgeRestriction(userId);
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
return new RelatedSeriesDto()
{

View file

@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks;
using API.DTOs.Metadata;
using API.Entities;
using API.Extensions;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using Microsoft.EntityFrameworkCore;
@ -13,11 +14,10 @@ public interface ITagRepository
{
void Attach(Tag tag);
void Remove(Tag tag);
Task<Tag> FindByNameAsync(string tagName);
Task<IList<Tag>> GetAllTagsAsync();
Task<IList<TagDto>> GetAllTagDtosAsync();
Task<IList<TagDto>> GetAllTagDtosAsync(int userId);
Task RemoveAllTagNoLongerAssociated(bool removeExternal = false);
Task<IList<TagDto>> GetAllTagDtosForLibrariesAsync(IList<int> libraryIds);
Task<IList<TagDto>> GetAllTagDtosForLibrariesAsync(IList<int> libraryIds, int userId);
}
public class TagRepository : ITagRepository
@ -41,13 +41,6 @@ public class TagRepository : ITagRepository
_context.Tag.Remove(tag);
}
public async Task<Tag> FindByNameAsync(string tagName)
{
var normalizedName = Services.Tasks.Scanner.Parser.Parser.Normalize(tagName);
return await _context.Tag
.FirstOrDefaultAsync(g => g.NormalizedTitle.Equals(normalizedName));
}
public async Task RemoveAllTagNoLongerAssociated(bool removeExternal = false)
{
var tagsWithNoConnections = await _context.Tag
@ -62,10 +55,12 @@ public class TagRepository : ITagRepository
await _context.SaveChangesAsync();
}
public async Task<IList<TagDto>> GetAllTagDtosForLibrariesAsync(IList<int> libraryIds)
public async Task<IList<TagDto>> GetAllTagDtosForLibrariesAsync(IList<int> libraryIds, int userId)
{
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
return await _context.Series
.Where(s => libraryIds.Contains(s.LibraryId))
.RestrictAgainstAgeRestriction(userRating)
.SelectMany(s => s.Metadata.Tags)
.AsSplitQuery()
.Distinct()
@ -80,10 +75,12 @@ public class TagRepository : ITagRepository
return await _context.Tag.ToListAsync();
}
public async Task<IList<TagDto>> GetAllTagDtosAsync()
public async Task<IList<TagDto>> GetAllTagDtosAsync(int userId)
{
var userRating = await _context.AppUser.GetUserAgeRestriction(userId);
return await _context.Tag
.AsNoTracking()
.RestrictAgainstAgeRestriction(userRating)
.OrderBy(t => t.Title)
.ProjectTo<TagDto>(_mapper.ConfigurationProvider)
.ToListAsync();