diff --git a/src/Managing.Application.Abstractions/Repositories/IAgentSummaryRepository.cs b/src/Managing.Application.Abstractions/Repositories/IAgentSummaryRepository.cs index 5e6c2461..22a66aa5 100644 --- a/src/Managing.Application.Abstractions/Repositories/IAgentSummaryRepository.cs +++ b/src/Managing.Application.Abstractions/Repositories/IAgentSummaryRepository.cs @@ -35,4 +35,10 @@ public interface IAgentSummaryRepository /// The user ID /// The new agent name Task UpdateAgentNameAsync(int userId, string agentName); + + /// + /// Gets the total count of agents + /// + /// Total number of agents + Task GetTotalAgentCount(); } \ No newline at end of file diff --git a/src/Managing.Application.Abstractions/Services/IAgentService.cs b/src/Managing.Application.Abstractions/Services/IAgentService.cs index 7685336d..edd9c8b4 100644 --- a/src/Managing.Application.Abstractions/Services/IAgentService.cs +++ b/src/Managing.Application.Abstractions/Services/IAgentService.cs @@ -21,4 +21,10 @@ public interface IAgentService /// The user ID /// The new agent name Task UpdateAgentSummaryNameAsync(int userId, string agentName); + + /// + /// Gets the total count of agents + /// + /// Total number of agents + Task GetTotalAgentCount(); } \ No newline at end of file diff --git a/src/Managing.Application/Agents/AgentService.cs b/src/Managing.Application/Agents/AgentService.cs index f4a7a46c..d2541273 100644 --- a/src/Managing.Application/Agents/AgentService.cs +++ b/src/Managing.Application/Agents/AgentService.cs @@ -145,4 +145,9 @@ public class AgentService : IAgentService throw; } } + + public async Task GetTotalAgentCount() + { + return await _agentSummaryRepository.GetTotalAgentCount(); + } } \ No newline at end of file diff --git a/src/Managing.Application/Grains/PlatformSummaryGrain.cs b/src/Managing.Application/Grains/PlatformSummaryGrain.cs index 7d7a5e01..76937453 100644 --- a/src/Managing.Application/Grains/PlatformSummaryGrain.cs +++ b/src/Managing.Application/Grains/PlatformSummaryGrain.cs @@ -99,11 +99,9 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable { _logger.LogInformation("Refreshing platform summary data"); - var agents = await _agentService.GetAllAgentSummaries(); var strategies = await _botService.GetBotsAsync(); // Calculate totals - var totalAgents = agents.Count(); var totalActiveStrategies = strategies.Count(s => s.Status == BotStatus.Running); // Calculate volume from strategies @@ -116,7 +114,6 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable var (totalOpenInterest, totalPositionCount) = await CalculatePositionMetricsAsync(); // Update state - _state.State.TotalAgents = totalAgents; _state.State.TotalActiveStrategies = totalActiveStrategies; // Only update volume if it hasn't been updated by events recently @@ -131,6 +128,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable _logger.LogDebug("Preserving event-updated volume: {Volume}", _state.State.TotalPlatformVolume); } + _state.State.TotalAgents = await _agentService.GetTotalAgentCount(); _state.State.TotalPlatformPnL = totalPnL; _state.State.OpenInterest = totalOpenInterest; _state.State.TotalLifetimePositionCount = totalPositionCount; diff --git a/src/Managing.Infrastructure.Database/PostgreSql/AgentSummaryRepository.cs b/src/Managing.Infrastructure.Database/PostgreSql/AgentSummaryRepository.cs index 44828cb1..7f64a4cc 100644 --- a/src/Managing.Infrastructure.Database/PostgreSql/AgentSummaryRepository.cs +++ b/src/Managing.Infrastructure.Database/PostgreSql/AgentSummaryRepository.cs @@ -318,4 +318,9 @@ public class AgentSummaryRepository : IAgentSummaryRepository userId, agentName); } } + + public async Task GetTotalAgentCount() + { + return await _context.AgentSummaries.CountAsync(); + } } \ No newline at end of file