Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 49b232eaa8 | |||
| 3faecbb639 |
@@ -3,6 +3,7 @@ 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;
|
||||||
|
|
||||||
@@ -11,12 +12,12 @@ namespace NexusReader.Infrastructure.Identity;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TokenLimitHandler : AuthorizationHandler<TokenLimitRequirement>
|
public class TokenLimitHandler : AuthorizationHandler<TokenLimitRequirement>
|
||||||
{
|
{
|
||||||
private readonly AppDbContext _dbContext;
|
private readonly IDbContextFactory<AppDbContext> _dbContextFactory;
|
||||||
private readonly UserManager<NexusUser> _userManager;
|
private readonly UserManager<NexusUser> _userManager;
|
||||||
|
|
||||||
public TokenLimitHandler(AppDbContext dbContext, UserManager<NexusUser> userManager)
|
public TokenLimitHandler(IDbContextFactory<AppDbContext> dbContextFactory, UserManager<NexusUser> userManager)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContextFactory = dbContextFactory;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
|
|
||||||
namespace NexusReader.UI.Shared.Services;
|
namespace NexusReader.UI.Shared.Services;
|
||||||
|
|
||||||
public sealed class KnowledgeCoordinator : IDisposable
|
public sealed partial 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 class KnowledgeCoordinator : IDisposable
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(fullContent)) return;
|
if (string.IsNullOrWhiteSpace(fullContent)) return;
|
||||||
|
|
||||||
_logger.LogInformation("[KnowledgeCoordinator] Generating full page graph for tenant: {TenantId}", tenantId);
|
LogGeneratingGraph(tenantId);
|
||||||
|
|
||||||
_graphService.Clear();
|
_graphService.Clear();
|
||||||
_graphService.SetLoading(true);
|
_graphService.SetLoading(true);
|
||||||
@@ -67,7 +67,7 @@ public sealed class KnowledgeCoordinator : IDisposable
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "[KnowledgeCoordinator] Error generating graph for tenant: {TenantId}", tenantId);
|
LogGraphError(ex, tenantId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public sealed 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);
|
||||||
_logger.LogInformation("[KnowledgeCoordinator] Requesting summary and quiz for tenant: {TenantId}", tenantId);
|
LogRequestingSummary(tenantId);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await _knowledgeService.GetSummaryAndQuizAsync(content, tenantId);
|
var result = await _knowledgeService.GetSummaryAndQuizAsync(content, tenantId);
|
||||||
@@ -96,11 +96,11 @@ public sealed class KnowledgeCoordinator : IDisposable
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogWarning("[KnowledgeCoordinator] Failed to get summary and quiz for tenant: {TenantId}", tenantId);
|
LogSummaryWarning(tenantId);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "[KnowledgeCoordinator] Error requesting summary and quiz for tenant: {TenantId}", tenantId);
|
LogSummaryError(ex, tenantId);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -119,4 +119,19 @@ public sealed 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,8 @@ 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 dbContext = services.GetRequiredService<NexusReader.Infrastructure.Persistence.AppDbContext>();
|
var dbContextFactory = services.GetRequiredService<IDbContextFactory<NexusReader.Infrastructure.Persistence.AppDbContext>>();
|
||||||
|
using var dbContext = await dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
int maxRetries = 5;
|
int maxRetries = 5;
|
||||||
int delayMs = 2000;
|
int delayMs = 2000;
|
||||||
|
|||||||
Reference in New Issue
Block a user