diff --git a/src/Data/Repositories/Interfaces/INodeRepository.cs b/src/Data/Repositories/Interfaces/INodeRepository.cs index eb07845e..60cb6351 100644 --- a/src/Data/Repositories/Interfaces/INodeRepository.cs +++ b/src/Data/Repositories/Interfaces/INodeRepository.cs @@ -24,7 +24,7 @@ namespace NodeGuard.Data.Repositories.Interfaces; public interface INodeRepository { - Task GetById(int id); + Task GetById(int id, bool includeRelatedData = true); Task GetByPubkey(string key); diff --git a/src/Data/Repositories/NodeRepository.cs b/src/Data/Repositories/NodeRepository.cs index e3737599..29b709b0 100644 --- a/src/Data/Repositories/NodeRepository.cs +++ b/src/Data/Repositories/NodeRepository.cs @@ -43,17 +43,23 @@ public NodeRepository(IRepository repository, _mapper = mapper; } - public async Task GetById(int id) + public async Task GetById(int id, bool includeRelatedData = true) { await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync(); - return await applicationDbContext.Nodes - .Include(node => node.Users) - .ThenInclude(user => user.Keys) - .ThenInclude(key => key.Wallets) - .Include(x => x.FundsDestinationWallet) - .ThenInclude(x => x.Keys) - .SingleOrDefaultAsync(x => x.Id == id); + var query = applicationDbContext.Nodes.AsQueryable(); + + if (includeRelatedData) + { + query = query + .Include(node => node.Users) + .ThenInclude(user => user.Keys) + .ThenInclude(key => key.Wallets) + .Include(x => x.FundsDestinationWallet) + .ThenInclude(x => x.Keys); + } + + return await query.SingleOrDefaultAsync(x => x.Id == id); } public async Task GetByPubkey(string key) diff --git a/src/Jobs/NodeHtlcSubscribeJob.cs b/src/Jobs/NodeHtlcSubscribeJob.cs index 1970bb5f..fcb12e62 100644 --- a/src/Jobs/NodeHtlcSubscribeJob.cs +++ b/src/Jobs/NodeHtlcSubscribeJob.cs @@ -70,7 +70,7 @@ public async Task Execute(IJobExecutionContext context) try { - var node = await _nodeRepository.GetById(nodeId); + var node = await _nodeRepository.GetById(nodeId, false); if (!IsNodeEligible(node)) { _logger.LogInformation("Node {NodeId} is not eligible for HTLC monitoring", nodeId); @@ -80,7 +80,7 @@ public async Task Execute(IJobExecutionContext context) var stream = _lightningRouterService.SubscribeHtlcEvents(node!); while (await stream.ResponseStream.MoveNext(context.CancellationToken)) { - node = await _nodeRepository.GetById(nodeId); + node = await _nodeRepository.GetById(nodeId, false); try {