mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
Cleaned up some warnings and implemented re-occuring scan libraries task. Customization of task schedules is in v0.2.
This commit is contained in:
parent
e180032a8e
commit
3c8e4b2240
@ -22,18 +22,16 @@ namespace API.Controllers
|
|||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
private readonly ITaskScheduler _taskScheduler;
|
private readonly ITaskScheduler _taskScheduler;
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
private readonly ICacheService _cacheService;
|
|
||||||
|
|
||||||
public LibraryController(IDirectoryService directoryService,
|
public LibraryController(IDirectoryService directoryService,
|
||||||
ILogger<LibraryController> logger, IMapper mapper, ITaskScheduler taskScheduler,
|
ILogger<LibraryController> logger, IMapper mapper, ITaskScheduler taskScheduler,
|
||||||
IUnitOfWork unitOfWork, ICacheService cacheService)
|
IUnitOfWork unitOfWork)
|
||||||
{
|
{
|
||||||
_directoryService = directoryService;
|
_directoryService = directoryService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_taskScheduler = taskScheduler;
|
_taskScheduler = taskScheduler;
|
||||||
_unitOfWork = unitOfWork;
|
_unitOfWork = unitOfWork;
|
||||||
_cacheService = cacheService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -4,8 +4,6 @@ using System.Threading.Tasks;
|
|||||||
using API.DTOs;
|
using API.DTOs;
|
||||||
using API.Extensions;
|
using API.Extensions;
|
||||||
using API.Interfaces;
|
using API.Interfaces;
|
||||||
using AutoMapper;
|
|
||||||
using Hangfire;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@ -16,15 +14,12 @@ namespace API.Controllers
|
|||||||
{
|
{
|
||||||
private readonly ILogger<SeriesController> _logger;
|
private readonly ILogger<SeriesController> _logger;
|
||||||
private readonly ITaskScheduler _taskScheduler;
|
private readonly ITaskScheduler _taskScheduler;
|
||||||
private readonly ICacheService _cacheService;
|
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
|
||||||
public SeriesController(ILogger<SeriesController> logger, ITaskScheduler taskScheduler,
|
public SeriesController(ILogger<SeriesController> logger, ITaskScheduler taskScheduler, IUnitOfWork unitOfWork)
|
||||||
ICacheService cacheService, IUnitOfWork unitOfWork)
|
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_taskScheduler = taskScheduler;
|
_taskScheduler = taskScheduler;
|
||||||
_cacheService = cacheService;
|
|
||||||
_unitOfWork = unitOfWork;
|
_unitOfWork = unitOfWork;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,11 +39,6 @@ namespace API.Data
|
|||||||
.WithOne(u => u.Role)
|
.WithOne(u => u.Role)
|
||||||
.HasForeignKey(ur => ur.RoleId)
|
.HasForeignKey(ur => ur.RoleId)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
// AppUsers have Libraries, not other way around
|
|
||||||
// builder.Entity<Library>()
|
|
||||||
// .HasMany(p => p.AppUsers)
|
|
||||||
// .WithMany(p => p.Libraries)
|
|
||||||
// .UsingEntity(j => j.ToTable("AppUserLibrary"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnEntityTracked(object sender, EntityTrackedEventArgs e)
|
void OnEntityTracked(object sender, EntityTrackedEventArgs e)
|
||||||
|
@ -63,17 +63,6 @@ namespace API.Data
|
|||||||
|
|
||||||
public async Task<IEnumerable<SeriesDto>> GetSeriesDtoForLibraryIdAsync(int libraryId, int userId)
|
public async Task<IEnumerable<SeriesDto>> GetSeriesDtoForLibraryIdAsync(int libraryId, int userId)
|
||||||
{
|
{
|
||||||
// if (userId > 0)
|
|
||||||
// {
|
|
||||||
// return await _context.AppUserProgresses
|
|
||||||
// .Include(p => p.Series)
|
|
||||||
// .Where(p => p.AppUserId == userId && p.Series.LibraryId == libraryId)
|
|
||||||
// .Select(p => p.Series)
|
|
||||||
// .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
|
||||||
// //.Select(s => s.PagesRead = )
|
|
||||||
// .ToListAsync();
|
|
||||||
// }
|
|
||||||
|
|
||||||
var sw = Stopwatch.StartNew();
|
var sw = Stopwatch.StartNew();
|
||||||
var series = await _context.Series
|
var series = await _context.Series
|
||||||
.Where(s => s.LibraryId == libraryId)
|
.Where(s => s.LibraryId == libraryId)
|
||||||
|
@ -20,7 +20,7 @@ namespace API.Data
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ISeriesRepository SeriesRepository => new SeriesRepository(_context, _mapper);
|
public ISeriesRepository SeriesRepository => new SeriesRepository(_context, _mapper);
|
||||||
public IUserRepository UserRepository => new UserRepository(_context, _mapper, _userManager);
|
public IUserRepository UserRepository => new UserRepository(_context, _userManager);
|
||||||
public ILibraryRepository LibraryRepository => new LibraryRepository(_context, _mapper);
|
public ILibraryRepository LibraryRepository => new LibraryRepository(_context, _mapper);
|
||||||
|
|
||||||
public async Task<bool> Complete()
|
public async Task<bool> Complete()
|
||||||
|
@ -5,8 +5,6 @@ using API.Constants;
|
|||||||
using API.DTOs;
|
using API.DTOs;
|
||||||
using API.Entities;
|
using API.Entities;
|
||||||
using API.Interfaces;
|
using API.Interfaces;
|
||||||
using AutoMapper;
|
|
||||||
using AutoMapper.QueryableExtensions;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@ -15,13 +13,11 @@ namespace API.Data
|
|||||||
public class UserRepository : IUserRepository
|
public class UserRepository : IUserRepository
|
||||||
{
|
{
|
||||||
private readonly DataContext _context;
|
private readonly DataContext _context;
|
||||||
private readonly IMapper _mapper;
|
|
||||||
private readonly UserManager<AppUser> _userManager;
|
private readonly UserManager<AppUser> _userManager;
|
||||||
|
|
||||||
public UserRepository(DataContext context, IMapper mapper, UserManager<AppUser> userManager)
|
public UserRepository(DataContext context, UserManager<AppUser> userManager)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_mapper = mapper;
|
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,13 +73,5 @@ namespace API.Data
|
|||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public async Task<MemberDto> GetMemberAsync(string username)
|
|
||||||
// {
|
|
||||||
// return await _context.Users.Where(x => x.UserName == username)
|
|
||||||
// .Include(x => x.Libraries)
|
|
||||||
// .ProjectTo<MemberDto>(_mapper.ConfigurationProvider)
|
|
||||||
// .SingleOrDefaultAsync();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace API.Entities
|
namespace API.Entities
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using API.Entities.Interfaces;
|
using API.Entities.Interfaces;
|
||||||
|
|
||||||
namespace API.Entities
|
namespace API.Entities
|
||||||
|
@ -10,13 +10,6 @@ namespace API.Helpers
|
|||||||
public AutoMapperProfiles()
|
public AutoMapperProfiles()
|
||||||
{
|
{
|
||||||
CreateMap<LibraryDto, Library>();
|
CreateMap<LibraryDto, Library>();
|
||||||
// .ForMember(dest => dest.Folders,
|
|
||||||
// opt =>
|
|
||||||
// opt.MapFrom(src => src.Folders.Select(x => new FolderPath()
|
|
||||||
// {
|
|
||||||
// Path = x,
|
|
||||||
// //LibraryId = src.Id
|
|
||||||
// }).ToList()));
|
|
||||||
|
|
||||||
CreateMap<Volume, VolumeDto>();
|
CreateMap<Volume, VolumeDto>();
|
||||||
|
|
||||||
|
@ -13,9 +13,6 @@ namespace API.Interfaces
|
|||||||
/// <returns>List of folder names</returns>
|
/// <returns>List of folder names</returns>
|
||||||
IEnumerable<string> ListDirectory(string rootPath);
|
IEnumerable<string> ListDirectory(string rootPath);
|
||||||
|
|
||||||
|
|
||||||
//IList<string> ListFiles(string rootPath);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Given a library id, scans folders for said library. Parses files and generates DB updates. Will overwrite
|
/// Given a library id, scans folders for said library. Parses files and generates DB updates. Will overwrite
|
||||||
/// cover images if forceUpdate is true.
|
/// cover images if forceUpdate is true.
|
||||||
@ -24,6 +21,8 @@ namespace API.Interfaces
|
|||||||
/// <param name="forceUpdate">Force overwriting for cover images</param>
|
/// <param name="forceUpdate">Force overwriting for cover images</param>
|
||||||
void ScanLibrary(int libraryId, bool forceUpdate);
|
void ScanLibrary(int libraryId, bool forceUpdate);
|
||||||
|
|
||||||
|
void ScanLibraries();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the path a volume would be extracted to.
|
/// Returns the path a volume would be extracted to.
|
||||||
/// Deprecated.
|
/// Deprecated.
|
||||||
|
@ -13,7 +13,7 @@ namespace API.Interfaces
|
|||||||
Series GetSeriesByName(string name);
|
Series GetSeriesByName(string name);
|
||||||
Task<IEnumerable<SeriesDto>> GetSeriesDtoForLibraryIdAsync(int libraryId, int userId);
|
Task<IEnumerable<SeriesDto>> GetSeriesDtoForLibraryIdAsync(int libraryId, int userId);
|
||||||
Task<IEnumerable<Series>> GetSeriesForLibraryIdAsync(int libraryId);
|
Task<IEnumerable<Series>> GetSeriesForLibraryIdAsync(int libraryId);
|
||||||
Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId, int userId = 0);
|
Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId, int userId);
|
||||||
IEnumerable<Volume> GetVolumes(int seriesId);
|
IEnumerable<Volume> GetVolumes(int seriesId);
|
||||||
Task<SeriesDto> GetSeriesDtoByIdAsync(int seriesId);
|
Task<SeriesDto> GetSeriesDtoByIdAsync(int seriesId);
|
||||||
|
|
||||||
|
@ -210,7 +210,16 @@ namespace API.Services
|
|||||||
return volumes;
|
return volumes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ScanLibrary(int libraryId, bool forceUpdate)
|
public void ScanLibraries()
|
||||||
|
{
|
||||||
|
var libraries = Task.Run(() => _unitOfWork.LibraryRepository.GetLibrariesAsync()).Result.ToList();
|
||||||
|
foreach (var lib in libraries)
|
||||||
|
{
|
||||||
|
ScanLibrary(lib.Id, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ScanLibrary(int libraryId, bool forceUpdate)
|
||||||
{
|
{
|
||||||
var sw = Stopwatch.StartNew();
|
var sw = Stopwatch.StartNew();
|
||||||
Library library;
|
Library library;
|
||||||
|
@ -8,21 +8,19 @@ namespace API.Services
|
|||||||
{
|
{
|
||||||
private readonly ICacheService _cacheService;
|
private readonly ICacheService _cacheService;
|
||||||
private readonly ILogger<TaskScheduler> _logger;
|
private readonly ILogger<TaskScheduler> _logger;
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
|
||||||
private readonly IDirectoryService _directoryService;
|
private readonly IDirectoryService _directoryService;
|
||||||
public BackgroundJobServer Client => new BackgroundJobServer();
|
public BackgroundJobServer Client => new BackgroundJobServer();
|
||||||
|
|
||||||
public TaskScheduler(ICacheService cacheService, ILogger<TaskScheduler> logger,
|
public TaskScheduler(ICacheService cacheService, ILogger<TaskScheduler> logger,
|
||||||
IUnitOfWork unitOfWork, IDirectoryService directoryService)
|
IDirectoryService directoryService)
|
||||||
{
|
{
|
||||||
_cacheService = cacheService;
|
_cacheService = cacheService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_unitOfWork = unitOfWork;
|
|
||||||
_directoryService = directoryService;
|
_directoryService = directoryService;
|
||||||
|
|
||||||
_logger.LogInformation("Scheduling/Updating cache cleanup on a daily basis.");
|
_logger.LogInformation("Scheduling/Updating cache cleanup on a daily basis.");
|
||||||
RecurringJob.AddOrUpdate(() => _cacheService.Cleanup(), Cron.Daily);
|
RecurringJob.AddOrUpdate(() => _cacheService.Cleanup(), Cron.Daily);
|
||||||
//RecurringJob.AddOrUpdate(() => scanService.ScanLibraries(), Cron.Daily);
|
RecurringJob.AddOrUpdate(() => directoryService.ScanLibraries(), Cron.Daily);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ScanLibrary(int libraryId, bool forceUpdate = false)
|
public void ScanLibrary(int libraryId, bool forceUpdate = false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user