diff --git a/BTCPayServer/Services/Notifications/NotificationManager.cs b/BTCPayServer/Services/Notifications/NotificationManager.cs index db0dac562..06764dbe1 100644 --- a/BTCPayServer/Services/Notifications/NotificationManager.cs +++ b/BTCPayServer/Services/Notifications/NotificationManager.cs @@ -8,6 +8,7 @@ using BTCPayServer.Data; using BTCPayServer.Models.NotificationViewModels; using Google.Apis.Storage.v1.Data; using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Newtonsoft.Json; @@ -31,20 +32,20 @@ namespace BTCPayServer.Services.Notifications } private const int _cacheExpiryMs = 5000; - public NotificationSummaryViewModel GetSummaryNotifications(ClaimsPrincipal user) + public async Task GetSummaryNotifications(ClaimsPrincipal user) { var userId = _userManager.GetUserId(user); if (_memoryCache.TryGetValue(userId, out var obj)) return obj; - var resp = FetchNotificationsFromDb(userId); + var resp = await FetchNotificationsFromDb(userId); _memoryCache.Set(userId, resp, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMilliseconds(_cacheExpiryMs))); return resp; } - private NotificationSummaryViewModel FetchNotificationsFromDb(string userId) + private async Task FetchNotificationsFromDb(string userId) { var resp = new NotificationSummaryViewModel(); using (var _db = _factory.CreateContext()) @@ -57,10 +58,11 @@ namespace BTCPayServer.Services.Notifications { try { - resp.Last5 = _db.Notifications + resp.Last5 = (await _db.Notifications .Where(a => a.ApplicationUserId == userId && !a.Seen) .OrderByDescending(a => a.Created) .Take(5) + .ToListAsync()) .Select(a => ToViewModel(a)) .ToList(); } diff --git a/BTCPayServer/Views/Shared/LayoutPartials/NotificationsNavItem.cshtml b/BTCPayServer/Views/Shared/LayoutPartials/NotificationsNavItem.cshtml index ed1e6dade..a563fb255 100644 --- a/BTCPayServer/Views/Shared/LayoutPartials/NotificationsNavItem.cshtml +++ b/BTCPayServer/Views/Shared/LayoutPartials/NotificationsNavItem.cshtml @@ -1,7 +1,7 @@ @inject BTCPayServer.Services.Notifications.NotificationManager notificationManager @{ - var notificationModel = notificationManager.GetSummaryNotifications(User); + var notificationModel = await notificationManager.GetSummaryNotifications(User); } @if (notificationModel.UnseenCount > 0)