fix: prevent potential component state updates after disposal and implement dedicated repository for quiz results

This commit is contained in:
2026-05-26 14:14:51 +02:00
parent 381f26ed3e
commit a2aecf7dd3
14 changed files with 323 additions and 132 deletions
@@ -5,8 +5,8 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NexusReader.Application.Abstractions.Messaging;
using NexusReader.Application.Abstractions.Persistence;
using NexusReader.Application.Abstractions.Services;
using NexusReader.Data.Persistence;
namespace NexusReader.Application.Commands.Library;
@@ -18,20 +18,20 @@ public record ProcessEbookCommand(
public class ProcessEbookCommandHandler : IRequestHandler<ProcessEbookCommand, Result<bool>>
{
private readonly IDbContextFactory<AppDbContext> _dbContextFactory;
private readonly IEbookRepository _ebookRepository;
private readonly IKnowledgeService _knowledgeService;
private readonly IEpubExtractor _epubExtractor;
private readonly ISyncBroadcaster _broadcaster;
private readonly ILogger<ProcessEbookCommandHandler> _logger;
public ProcessEbookCommandHandler(
IDbContextFactory<AppDbContext> dbContextFactory,
IEbookRepository ebookRepository,
IKnowledgeService knowledgeService,
IEpubExtractor epubExtractor,
ISyncBroadcaster broadcaster,
ILogger<ProcessEbookCommandHandler> logger)
{
_dbContextFactory = dbContextFactory;
_ebookRepository = ebookRepository;
_knowledgeService = knowledgeService;
_epubExtractor = epubExtractor;
_broadcaster = broadcaster;
@@ -46,8 +46,7 @@ public class ProcessEbookCommandHandler : IRequestHandler<ProcessEbookCommand, R
{
await _broadcaster.BroadcastIngestionProgressAsync(request.UserId, "Wyszukiwanie e-booka w bazie danych...", 0.05, cancellationToken);
using var dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
var ebook = await dbContext.Ebooks.FindAsync(new object[] { request.EbookId }, cancellationToken);
var ebook = await _ebookRepository.FindByIdAsync(request.EbookId, cancellationToken);
if (ebook == null)
{
_logger.LogError("[ProcessEbook] Ebook not found in database: {EbookId}", request.EbookId);
@@ -122,7 +121,7 @@ public class ProcessEbookCommandHandler : IRequestHandler<ProcessEbookCommand, R
// Mark the ebook as ready
ebook.IsReadyForReading = true;
await dbContext.SaveChangesAsync(cancellationToken);
await _ebookRepository.SaveChangesAsync(cancellationToken);
_logger.LogInformation("[ProcessEbook] Ingestion and vector indexing completed for: {Title}", ebook.Title);