mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
dispose streamer properly
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Net.Http;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Controllers;
|
using BTCPayServer.Controllers;
|
||||||
|
using BTCPayServer.Crowdfund;
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
using BTCPayServer.Events;
|
using BTCPayServer.Events;
|
||||||
using BTCPayServer.Hubs;
|
using BTCPayServer.Hubs;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using BTCPayServer.Crowdfund;
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
using BTCPayServer.Filters;
|
using BTCPayServer.Filters;
|
||||||
using BTCPayServer.Hubs;
|
using BTCPayServer.Hubs;
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ using System;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Controllers;
|
using BTCPayServer.Controllers;
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
using BTCPayServer.Events;
|
using BTCPayServer.Events;
|
||||||
|
using BTCPayServer.Hubs;
|
||||||
using BTCPayServer.Models.AppViewModels;
|
using BTCPayServer.Models.AppViewModels;
|
||||||
using BTCPayServer.Payments;
|
using BTCPayServer.Payments;
|
||||||
using BTCPayServer.Rating;
|
using BTCPayServer.Rating;
|
||||||
@@ -16,14 +16,11 @@ using BTCPayServer.Services.Rates;
|
|||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Primitives;
|
|
||||||
using NBitcoin;
|
using NBitcoin;
|
||||||
using YamlDotNet.Core;
|
|
||||||
|
|
||||||
namespace BTCPayServer.Hubs
|
namespace BTCPayServer.Crowdfund
|
||||||
{
|
{
|
||||||
public class
|
public class CrowdfundHubStreamer: IDisposable
|
||||||
CrowdfundHubStreamer
|
|
||||||
{
|
{
|
||||||
public const string CrowdfundInvoiceOrderIdPrefix = "crowdfund-app_";
|
public const string CrowdfundInvoiceOrderIdPrefix = "crowdfund-app_";
|
||||||
private readonly EventAggregator _EventAggregator;
|
private readonly EventAggregator _EventAggregator;
|
||||||
@@ -38,6 +35,8 @@ namespace BTCPayServer.Hubs
|
|||||||
private readonly ConcurrentDictionary<string,(string appId, bool useAllStoreInvoices,bool useInvoiceAmount)> _QuickAppInvoiceLookup =
|
private readonly ConcurrentDictionary<string,(string appId, bool useAllStoreInvoices,bool useInvoiceAmount)> _QuickAppInvoiceLookup =
|
||||||
new ConcurrentDictionary<string, (string appId, bool useAllStoreInvoices, bool useInvoiceAmount)>();
|
new ConcurrentDictionary<string, (string appId, bool useAllStoreInvoices, bool useInvoiceAmount)>();
|
||||||
|
|
||||||
|
private List<IEventAggregatorSubscription> _Subscriptions;
|
||||||
|
|
||||||
public CrowdfundHubStreamer(EventAggregator eventAggregator,
|
public CrowdfundHubStreamer(EventAggregator eventAggregator,
|
||||||
IHubContext<CrowdfundHub> hubContext,
|
IHubContext<CrowdfundHub> hubContext,
|
||||||
IMemoryCache memoryCache,
|
IMemoryCache memoryCache,
|
||||||
@@ -116,13 +115,15 @@ namespace BTCPayServer.Hubs
|
|||||||
|
|
||||||
private void SubscribeToEvents()
|
private void SubscribeToEvents()
|
||||||
{
|
{
|
||||||
|
_Subscriptions = new List<IEventAggregatorSubscription>()
|
||||||
_EventAggregator.Subscribe<InvoiceEvent>(OnInvoiceEvent);
|
{
|
||||||
|
_EventAggregator.Subscribe<InvoiceEvent>(OnInvoiceEvent),
|
||||||
_EventAggregator.Subscribe<AppsController.CrowdfundAppUpdated>(updated =>
|
_EventAggregator.Subscribe<AppsController.CrowdfundAppUpdated>(updated =>
|
||||||
{
|
{
|
||||||
UpdateLookup(updated.AppId, updated.StoreId, updated.Settings);
|
UpdateLookup(updated.AppId, updated.StoreId, updated.Settings);
|
||||||
InvalidateCacheForApp(updated.AppId);
|
InvalidateCacheForApp(updated.AppId);
|
||||||
});
|
})
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetCacheKey(string appId)
|
private string GetCacheKey(string appId)
|
||||||
@@ -361,5 +362,10 @@ namespace BTCPayServer.Hubs
|
|||||||
StartDate = startDate
|
StartDate = startDate
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_Subscriptions.ForEach(subscription => subscription.Dispose());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ using BTCPayServer.Logging;
|
|||||||
using BTCPayServer.HostedServices;
|
using BTCPayServer.HostedServices;
|
||||||
using Meziantou.AspNetCore.BundleTagHelpers;
|
using Meziantou.AspNetCore.BundleTagHelpers;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
using BTCPayServer.Crowdfund;
|
||||||
using BTCPayServer.Hubs;
|
using BTCPayServer.Hubs;
|
||||||
using BTCPayServer.Payments.Changelly;
|
using BTCPayServer.Payments.Changelly;
|
||||||
using BTCPayServer.Payments.Lightning;
|
using BTCPayServer.Payments.Lightning;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@using BTCPayServer.Hubs
|
@using BTCPayServer.Crowdfund
|
||||||
|
@using BTCPayServer.Hubs
|
||||||
@addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers
|
@addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers
|
||||||
@model UpdateCrowdfundViewModel
|
@model UpdateCrowdfundViewModel
|
||||||
@{
|
@{
|
||||||
|
|||||||
Reference in New Issue
Block a user