3 Commits

3 changed files with 10 additions and 27 deletions
@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using NexusReader.Domain.Entities; using NexusReader.Domain.Entities;
using NexusReader.Infrastructure.Persistence; using NexusReader.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
namespace NexusReader.Infrastructure.Identity; namespace NexusReader.Infrastructure.Identity;
@@ -12,12 +11,12 @@ namespace NexusReader.Infrastructure.Identity;
/// </summary> /// </summary>
public class TokenLimitHandler : AuthorizationHandler<TokenLimitRequirement> public class TokenLimitHandler : AuthorizationHandler<TokenLimitRequirement>
{ {
private readonly IDbContextFactory<AppDbContext> _dbContextFactory; private readonly AppDbContext _dbContext;
private readonly UserManager<NexusUser> _userManager; private readonly UserManager<NexusUser> _userManager;
public TokenLimitHandler(IDbContextFactory<AppDbContext> dbContextFactory, UserManager<NexusUser> userManager) public TokenLimitHandler(AppDbContext dbContext, UserManager<NexusUser> userManager)
{ {
_dbContextFactory = dbContextFactory; _dbContext = dbContext;
_userManager = userManager; _userManager = userManager;
} }
@@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging;
namespace NexusReader.UI.Shared.Services; namespace NexusReader.UI.Shared.Services;
public sealed partial class KnowledgeCoordinator : IDisposable public sealed class KnowledgeCoordinator : IDisposable
{ {
private readonly IKnowledgeService _knowledgeService; private readonly IKnowledgeService _knowledgeService;
private readonly IKnowledgeGraphService _graphService; private readonly IKnowledgeGraphService _graphService;
@@ -46,7 +46,7 @@ public sealed partial class KnowledgeCoordinator : IDisposable
{ {
if (string.IsNullOrWhiteSpace(fullContent)) return; if (string.IsNullOrWhiteSpace(fullContent)) return;
LogGeneratingGraph(tenantId); _logger.LogInformation("[KnowledgeCoordinator] Generating full page graph for tenant: {TenantId}", tenantId);
_graphService.Clear(); _graphService.Clear();
_graphService.SetLoading(true); _graphService.SetLoading(true);
@@ -67,7 +67,7 @@ public sealed partial class KnowledgeCoordinator : IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
LogGraphError(ex, tenantId); _logger.LogError(ex, "[KnowledgeCoordinator] Error generating graph for tenant: {TenantId}", tenantId);
} }
} }
@@ -80,7 +80,7 @@ public sealed partial class KnowledgeCoordinator : IDisposable
public async Task<KnowledgePacket?> RequestSummaryAndQuizAsync(string content, string tenantId = "global") public async Task<KnowledgePacket?> RequestSummaryAndQuizAsync(string content, string tenantId = "global")
{ {
_quizService.SetHydrating(true); _quizService.SetHydrating(true);
LogRequestingSummary(tenantId); _logger.LogInformation("[KnowledgeCoordinator] Requesting summary and quiz for tenant: {TenantId}", tenantId);
try try
{ {
var result = await _knowledgeService.GetSummaryAndQuizAsync(content, tenantId); var result = await _knowledgeService.GetSummaryAndQuizAsync(content, tenantId);
@@ -96,11 +96,11 @@ public sealed partial class KnowledgeCoordinator : IDisposable
return packet; return packet;
} }
LogSummaryWarning(tenantId); _logger.LogWarning("[KnowledgeCoordinator] Failed to get summary and quiz for tenant: {TenantId}", tenantId);
} }
catch (Exception ex) catch (Exception ex)
{ {
LogSummaryError(ex, tenantId); _logger.LogError(ex, "[KnowledgeCoordinator] Error requesting summary and quiz for tenant: {TenantId}", tenantId);
} }
finally finally
{ {
@@ -119,19 +119,4 @@ public sealed partial class KnowledgeCoordinator : IDisposable
{ {
_interactionService.OnNodeSelected -= HandleNodeSelected; _interactionService.OnNodeSelected -= HandleNodeSelected;
} }
[LoggerMessage(Level = LogLevel.Information, Message = "[KnowledgeCoordinator] Generating full page graph for tenant: {TenantId}")]
private partial void LogGeneratingGraph(string tenantId);
[LoggerMessage(Level = LogLevel.Error, Message = "[KnowledgeCoordinator] Error generating graph for tenant: {TenantId}")]
private partial void LogGraphError(Exception ex, string tenantId);
[LoggerMessage(Level = LogLevel.Information, Message = "[KnowledgeCoordinator] Requesting summary and quiz for tenant: {TenantId}")]
private partial void LogRequestingSummary(string tenantId);
[LoggerMessage(Level = LogLevel.Warning, Message = "[KnowledgeCoordinator] Failed to get summary and quiz for tenant: {TenantId}")]
private partial void LogSummaryWarning(string tenantId);
[LoggerMessage(Level = LogLevel.Error, Message = "[KnowledgeCoordinator] Error requesting summary and quiz for tenant: {TenantId}")]
private partial void LogSummaryError(Exception ex, string tenantId);
} }
+1 -2
View File
@@ -135,8 +135,7 @@ using (var scope = app.Services.CreateScope())
{ {
var services = scope.ServiceProvider; var services = scope.ServiceProvider;
var logger = services.GetRequiredService<ILogger<Program>>(); var logger = services.GetRequiredService<ILogger<Program>>();
var dbContextFactory = services.GetRequiredService<IDbContextFactory<NexusReader.Infrastructure.Persistence.AppDbContext>>(); var dbContext = services.GetRequiredService<NexusReader.Infrastructure.Persistence.AppDbContext>();
using var dbContext = await dbContextFactory.CreateDbContextAsync();
int maxRetries = 5; int maxRetries = 5;
int delayMs = 2000; int delayMs = 2000;