mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
* Some performance refactoring around getting Library and avoid a byte[] copy for getting cover images for epubs. * Initial commit. Rewrote the main series scan loop to use chunks of data at a time. Not fully shaken out. * Hooked in the ability for the UI to react to series being added or removed from the DB. * Cleaned up the messaging in the scan loop to be more clear. * Metadata scan and scan work as expected and populate data to the UI. There is a slow down in speed for overall operation. Scan series and refresh series metadata does not work fully. * Fixed a bug where MangaFiles were not having LastModified Updated correctly, meaning they were opening archives every scan. * Modified the code to be more realistic to the underlying file * Updated ScanService to properly handle deleted files and not result in a higher-level scan. * Shuffled around volume related repo apis to the volume repo rather than being in series. * Rewrote scan series to be much cleaner and more concise on the flow. Fixed an issue in UpdateVolumes such that the debug code to log out removed volumes could throw an exception and actually break updating volumes. * Refactored the code to set MangaFile last modified timestamp into the MangaFile entity. * Added Series Name to ScanSeries event * Added additional checks in ScanSeries to ensure we never go outside the library folder. Added extra debug messages for when a metadata refresh doesn't actually make changes and for when we regen cover images. * More logging statements saying where they originate from. Fixed a critical bug which caused only 1 chunk to ever be processed. * Fixed a concurrency issue with natural sorter which could cause issues in ArchiveService.cs. * Log cleanups * Fixed an issue with logging out total time of a scan. * Only show added toastrs for admins. When kicking off a refresh metadata for series, make sure we regenerate all cover images. * Code smells on benchmark despite it being ignored
84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
using System.Threading.Tasks;
|
|
using API.Data.Repositories;
|
|
using API.Entities;
|
|
using API.Interfaces;
|
|
using API.Interfaces.Repositories;
|
|
using AutoMapper;
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
namespace API.Data
|
|
{
|
|
public class UnitOfWork : IUnitOfWork
|
|
{
|
|
private readonly DataContext _context;
|
|
private readonly IMapper _mapper;
|
|
private readonly UserManager<AppUser> _userManager;
|
|
|
|
public UnitOfWork(DataContext context, IMapper mapper, UserManager<AppUser> userManager)
|
|
{
|
|
_context = context;
|
|
_mapper = mapper;
|
|
_userManager = userManager;
|
|
}
|
|
|
|
public ISeriesRepository SeriesRepository => new SeriesRepository(_context, _mapper);
|
|
public IUserRepository UserRepository => new UserRepository(_context, _userManager, _mapper);
|
|
public ILibraryRepository LibraryRepository => new LibraryRepository(_context, _mapper);
|
|
|
|
public IVolumeRepository VolumeRepository => new VolumeRepository(_context, _mapper);
|
|
|
|
public ISettingsRepository SettingsRepository => new SettingsRepository(_context, _mapper);
|
|
|
|
public IAppUserProgressRepository AppUserProgressRepository => new AppUserProgressRepository(_context);
|
|
public ICollectionTagRepository CollectionTagRepository => new CollectionTagRepository(_context, _mapper);
|
|
public IFileRepository FileRepository => new FileRepository(_context);
|
|
public IChapterRepository ChapterRepository => new ChapterRepository(_context, _mapper);
|
|
public IReadingListRepository ReadingListRepository => new ReadingListRepository(_context, _mapper);
|
|
|
|
/// <summary>
|
|
/// Commits changes to the DB. Completes the open transaction.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool Commit()
|
|
{
|
|
return _context.SaveChanges() > 0;
|
|
}
|
|
/// <summary>
|
|
/// Commits changes to the DB. Completes the open transaction.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> CommitAsync()
|
|
{
|
|
return await _context.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Is the DB Context aware of Changes in loaded entities
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool HasChanges()
|
|
{
|
|
return _context.ChangeTracker.HasChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rollback transaction
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> RollbackAsync()
|
|
{
|
|
await _context.DisposeAsync();
|
|
return true;
|
|
}
|
|
/// <summary>
|
|
/// Rollback transaction
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool Rollback()
|
|
{
|
|
_context.Dispose();
|
|
return true;
|
|
}
|
|
}
|
|
}
|