[CHANGE] No need to reload client from db if already loaded && can be loaded without checking library service

This commit is contained in:
max
2025-10-19 23:32:05 +02:00
parent 34e029ec79
commit 1555ae9f3d

View File

@@ -58,18 +58,18 @@ public class ClientService(IServiceScopeFactory scopeFactory, ILogger<ClientServ
return new ListResultReturn<YouTubeClientItem>(comparedClients, accountsResult.Total); return new ListResultReturn<YouTubeClientItem>(comparedClients, accountsResult.Total);
} }
public async Task<Result<YouTubeClient>> LoadClientByIdAsync(string id, bool forceLoad = false, CancellationToken cancellationToken = default) public async Task<Result<YouTubeClient>> LoadClientByIdAsync(string id, CancellationToken cancellationToken = default)
{ {
if (_loadedClients.TryGetValue(id, out var client))
{
return client;
}
if (_libraryService == null) if (_libraryService == null)
{ {
return ResultError.Fail("Library service is not initialized!."); return ResultError.Fail("Library service is not initialized!.");
} }
if (!forceLoad && _loadedClients.TryGetValue(id, out var client))
{
return client;
}
var clientResult = await _libraryService.GetChannelByIdAsync(id, cancellationToken); var clientResult = await _libraryService.GetChannelByIdAsync(id, cancellationToken);
if (!clientResult.IsSuccess) if (!clientResult.IsSuccess)
{ {