refactor(dotnet): separate collection read model service
Validators (Pushes and Pull Requests) / validate-ui-and-storage (push) Successful in 16s
Validators (Pushes and Pull Requests) / validate-core (push) Successful in 2m3s

This commit is contained in:
2026-07-13 00:44:43 +09:00
parent d610ecb57c
commit bccefed35e
6 changed files with 70 additions and 33 deletions
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;
using QuantEngine.Application.Interfaces;
using QuantEngine.Core.Interfaces;
using QuantEngine.Web.Services;
@@ -8,16 +9,16 @@ namespace QuantEngine.Web.Pages.Admin.Collection;
[Authorize(AuthenticationSchemes = AdminAuthDefaults.Scheme)]
public class IndexModel : PageModel
{
private readonly ICollectionRepository _collectionRepository;
private readonly ICollectionReadModelService _collectionReadModelService;
private readonly ILogger<IndexModel> _logger;
public List<CollectionRunRecord>? Runs { get; set; }
public List<PriceHistorySummaryRecord>? HistorySummary { get; set; }
public string? Message { get; set; }
public IndexModel(ICollectionRepository collectionRepository, ILogger<IndexModel> logger)
public IndexModel(ICollectionReadModelService collectionReadModelService, ILogger<IndexModel> logger)
{
_collectionRepository = collectionRepository;
_collectionReadModelService = collectionReadModelService;
_logger = logger;
}
@@ -25,8 +26,8 @@ public class IndexModel : PageModel
{
try
{
Runs = await _collectionRepository.GetRecentRunsAsync(limit: 20);
HistorySummary = await _collectionRepository.GetPriceHistorySummaryAsync();
Runs = await _collectionReadModelService.GetRecentRunsAsync(limit: 20);
HistorySummary = await _collectionReadModelService.GetPriceHistorySummaryAsync();
}
catch (Exception ex)
{
@@ -2,6 +2,7 @@ using System.IO;
using System.Reflection;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;
using QuantEngine.Application.Interfaces;
using QuantEngine.Core.Interfaces;
using QuantEngine.Web.Services;
@@ -11,7 +12,7 @@ namespace QuantEngine.Web.Pages.Admin.Dashboard;
public class IndexModel : PageModel
{
private readonly IWorkspaceRepository _workspaceRepository;
private readonly ICollectionRepository _collectionRepository;
private readonly ICollectionReadModelService _collectionReadModelService;
private readonly IWebHostEnvironment _environment;
private readonly ILogger<IndexModel> _logger;
@@ -95,12 +96,12 @@ public class IndexModel : PageModel
public IndexModel(
IWorkspaceRepository workspaceRepository,
ICollectionRepository collectionRepository,
ICollectionReadModelService collectionReadModelService,
IWebHostEnvironment environment,
ILogger<IndexModel> logger)
{
_workspaceRepository = workspaceRepository;
_collectionRepository = collectionRepository;
_collectionReadModelService = collectionReadModelService;
_environment = environment;
_logger = logger;
}
@@ -112,7 +113,7 @@ public class IndexModel : PageModel
var accounts = await _workspaceRepository.GetAccountsAsync();
ActiveUsersCount = accounts.Count(a => string.Equals(a.IsActive, "true", StringComparison.OrdinalIgnoreCase));
var dashboard = await _collectionRepository.GetDashboardStateAsync();
var dashboard = await _collectionReadModelService.GetDashboardStateAsync();
RecentRunsCount = string.IsNullOrEmpty(dashboard?.LastRunId) ? 0 : 1;
// These two queries only complete if the DB round-trip actually