mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
Bugfix/in progress (#452)
# Fixed - Fixed: Fixed an issue in In Progress where it would not pull the series with correct pagination due to the unique situation with the query. All series that are in progress should now return. ============================ * Fixed In Progress not showing for all series due to pagination bug * Version bump
This commit is contained in:
parent
01007dee28
commit
fd6fa2fce4
@ -168,8 +168,17 @@ namespace API.Controllers
|
||||
[HttpPost("in-progress")]
|
||||
public async Task<ActionResult<IEnumerable<SeriesDto>>> GetInProgress(FilterDto filterDto, [FromQuery] UserParams userParams, [FromQuery] int libraryId = 0)
|
||||
{
|
||||
// NOTE: This has to be done manually like this due to the DisinctBy requirement
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
return Ok((await _unitOfWork.SeriesRepository.GetInProgress(user.Id, libraryId, userParams, filterDto)).DistinctBy(s => s.Name));
|
||||
var results = await _unitOfWork.SeriesRepository.GetInProgress(user.Id, libraryId, userParams, filterDto);
|
||||
|
||||
var listResults = results.DistinctBy(s => s.Name).Skip((userParams.PageNumber - 1) * userParams.PageSize)
|
||||
.Take(userParams.PageSize).ToList();
|
||||
var pagedList = new PagedList<SeriesDto>(listResults, listResults.Count, userParams.PageNumber, userParams.PageSize);
|
||||
|
||||
Response.AddPaginationHeader(pagedList.CurrentPage, pagedList.PageSize, pagedList.TotalCount, pagedList.TotalPages);
|
||||
|
||||
return Ok(pagedList);
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
|
@ -323,7 +323,6 @@ namespace API.Data
|
||||
|
||||
var allQuery = _context.Series
|
||||
.Where(s => userLibraries.Contains(s.LibraryId) && formats.Contains(s.Format))
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(s => s.Created)
|
||||
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
||||
.AsNoTracking();
|
||||
@ -333,7 +332,6 @@ namespace API.Data
|
||||
|
||||
var query = _context.Series
|
||||
.Where(s => s.LibraryId == libraryId && formats.Contains(s.Format))
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(s => s.Created)
|
||||
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
||||
.AsNoTracking();
|
||||
@ -349,48 +347,55 @@ namespace API.Data
|
||||
/// <param name="userParams">Pagination information</param>
|
||||
/// <param name="filter">Optional (default null) filter on query</param>
|
||||
/// <returns></returns>
|
||||
public async Task<PagedList<SeriesDto>> GetInProgress(int userId, int libraryId, UserParams userParams, FilterDto filter)
|
||||
public async Task<IEnumerable<SeriesDto>> GetInProgress(int userId, int libraryId, UserParams userParams, FilterDto filter)
|
||||
{
|
||||
var formats = filter.GetSqlFilter();
|
||||
IList<int> userLibraries;
|
||||
if (libraryId == 0)
|
||||
{
|
||||
userLibraries = _context.Library
|
||||
.Include(l => l.AppUsers)
|
||||
.Where(library => library.AppUsers.Any(user => user.Id == userId))
|
||||
.AsNoTracking()
|
||||
.Select(library => library.Id)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
userLibraries = new List<int>() {libraryId};
|
||||
}
|
||||
|
||||
var series = _context.Series
|
||||
.Where(s => formats.Contains(s.Format))
|
||||
.Where(s => formats.Contains(s.Format) && userLibraries.Contains(s.LibraryId))
|
||||
.Join(_context.AppUserProgresses, s => s.Id, progress => progress.SeriesId, (s, progress) => new
|
||||
{
|
||||
Series = s,
|
||||
PagesRead = _context.AppUserProgresses.Where(s1 => s1.SeriesId == s.Id).Sum(s1 => s1.PagesRead),
|
||||
progress.AppUserId,
|
||||
LastModified = _context.AppUserProgresses.Where(p => p.Id == progress.Id).Max(p => p.LastModified)
|
||||
}).AsNoTracking();
|
||||
if (libraryId == 0)
|
||||
{
|
||||
var userLibraries = _context.Library
|
||||
.Include(l => l.AppUsers)
|
||||
.Where(library => library.AppUsers.Any(user => user.Id == userId))
|
||||
.AsNoTracking()
|
||||
.Select(library => library.Id)
|
||||
.ToList();
|
||||
series = series.Where(s => s.AppUserId == userId
|
||||
&& s.PagesRead > 0
|
||||
&& s.PagesRead < s.Series.Pages
|
||||
&& userLibraries.Contains(s.Series.LibraryId)
|
||||
&& formats.Contains(s.Series.Format));
|
||||
}
|
||||
else
|
||||
{
|
||||
series = series.Where(s => s.AppUserId == userId
|
||||
&& s.PagesRead > 0
|
||||
&& s.PagesRead < s.Series.Pages
|
||||
&& s.Series.LibraryId == libraryId
|
||||
&& formats.Contains(s.Series.Format));
|
||||
}
|
||||
})
|
||||
.AsNoTracking();
|
||||
|
||||
var retSeries = series
|
||||
|
||||
|
||||
var retSeries = series.Where(s => s.AppUserId == userId
|
||||
&& s.PagesRead > 0
|
||||
&& s.PagesRead < s.Series.Pages
|
||||
/*&& userLibraries.Contains(s.Series.LibraryId)*/
|
||||
/* && formats.Contains(s.Series.Format) */)
|
||||
.OrderByDescending(s => s.LastModified)
|
||||
.Select(s => s.Series)
|
||||
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
||||
.AsNoTracking();
|
||||
|
||||
return await PagedList<SeriesDto>.CreateAsync(retSeries, userParams.PageNumber, userParams.PageSize);
|
||||
// var retSeries = series
|
||||
// .OrderByDescending(s => s.LastModified)
|
||||
// .Select(s => s.Series)
|
||||
// .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
||||
// .AsNoTracking();
|
||||
// BUG: Pagination does not work for this query as when we pull the data back, we get multiple rows of the same series
|
||||
return await retSeries.ToListAsync();
|
||||
//return await PagedList<SeriesDto>.CreateAsync(retSeries, userParams.PageNumber, userParams.PageSize);
|
||||
}
|
||||
|
||||
public async Task<SeriesMetadataDto> GetSeriesMetadata(int seriesId)
|
||||
|
@ -7,7 +7,7 @@ namespace API.Extensions
|
||||
{
|
||||
public static class FilterDtoExtensions
|
||||
{
|
||||
private static IList<MangaFormat> _allFormats = Enum.GetValues<MangaFormat>();
|
||||
private static readonly IList<MangaFormat> AllFormats = Enum.GetValues<MangaFormat>();
|
||||
|
||||
public static IList<MangaFormat> GetSqlFilter(this FilterDto filter)
|
||||
{
|
||||
@ -19,10 +19,7 @@ namespace API.Extensions
|
||||
(MangaFormat) format
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return _allFormats;
|
||||
}
|
||||
return AllFormats;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace API.Interfaces
|
||||
|
||||
Task<byte[]> GetVolumeCoverImageAsync(int volumeId);
|
||||
Task<byte[]> GetSeriesCoverImageAsync(int seriesId);
|
||||
Task<PagedList<SeriesDto>> GetInProgress(int userId, int libraryId, UserParams userParams, FilterDto filter);
|
||||
Task<IEnumerable<SeriesDto>> GetInProgress(int userId, int libraryId, UserParams userParams, FilterDto filter);
|
||||
Task<PagedList<SeriesDto>> GetRecentlyAdded(int libraryId, int userId, UserParams userParams, FilterDto filter);
|
||||
Task<SeriesMetadataDto> GetSeriesMetadata(int seriesId);
|
||||
Task<PagedList<SeriesDto>> GetSeriesDtoForCollectionAsync(int collectionId, int userId, UserParams userParams);
|
||||
|
@ -4,7 +4,7 @@
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Company>kavitareader.com</Company>
|
||||
<Product>Kavita</Product>
|
||||
<AssemblyVersion>0.4.3.6</AssemblyVersion>
|
||||
<AssemblyVersion>0.4.3.7</AssemblyVersion>
|
||||
<NeutralLanguage>en</NeutralLanguage>
|
||||
</PropertyGroup>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user