Browse Source

fix: Delete users expired notifications

- When clearing expired notifications, user notifications should also be cleared at the same time
pull/1275/head
colin 7 months ago
parent
commit
d9f15240ee
  1. 4
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Domain/LINGYUN/Abp/Notifications/INotificationRepository.cs
  2. 4
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Domain/LINGYUN/Abp/Notifications/IUserNotificationRepository.cs
  3. 13
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Domain/LINGYUN/Abp/Notifications/NotificationStore.cs
  4. 3
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationRepository.cs
  5. 9
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreUserNotificationRepository.cs
  6. 4
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs
  7. 4
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NullNotificationStore.cs

4
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Domain/LINGYUN/Abp/Notifications/INotificationRepository.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -13,5 +14,6 @@ public interface INotificationRepository : IBasicRepository<Notification, long>
Task<List<Notification>> GetExpritionAsync(
int batchCount,
DateTime expritionTime,
CancellationToken cancellationToken = default);
}

4
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Domain/LINGYUN/Abp/Notifications/IUserNotificationRepository.cs

@ -29,6 +29,10 @@ public interface IUserNotificationRepository : IBasicRepository<UserNotification
int maxResultCount = 10,
CancellationToken cancellationToken = default);
Task<List<UserNotification>> GetListByNotificationIdssync(
IEnumerable<long> notificationIds,
CancellationToken cancellationToken = default);
Task<int> GetCountAsync(
Guid userId,
string filter = "",

13
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Domain/LINGYUN/Abp/Notifications/NotificationStore.cs

@ -102,15 +102,24 @@ public class NotificationStore : INotificationStore
}
}
public async virtual Task DeleteNotificationAsync(
public async virtual Task DeleteExpritionNotificationAsync(
Guid? tenantId,
int batchCount,
DateTime expritionTime,
CancellationToken cancellationToken = default)
{
using (var unitOfWork = _unitOfWorkManager.Begin())
using (_currentTenant.Change(tenantId))
{
var notitications = await _notificationRepository.GetExpritionAsync(batchCount, cancellationToken);
var notitications = await _notificationRepository.GetExpritionAsync(
batchCount, expritionTime, cancellationToken);
var userNotitications = await _userNotificationRepository.GetListByNotificationIdssync(
notitications.Select(notification => notification.Id));
// 清理过期通知
await _notificationRepository.DeleteManyAsync(notitications);
// 清理用户通知
await _userNotificationRepository.DeleteManyAsync(userNotitications);
await unitOfWork.CompleteAsync(cancellationToken);
}

3
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationRepository.cs

@ -21,10 +21,11 @@ public class EfCoreNotificationRepository : EfCoreRepository<INotificationsDbCon
public async Task<List<Notification>> GetExpritionAsync(
int batchCount,
DateTime expritionTime,
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(x => x.ExpirationTime < DateTime.Now)
.Where(x => x.ExpirationTime < expritionTime)
.OrderBy(x => x.ExpirationTime)
.Take(batchCount)
.ToListAsync(GetCancellationToken(cancellationToken));

9
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreUserNotificationRepository.cs

@ -74,6 +74,15 @@ public class EfCoreUserNotificationRepository : EfCoreRepository<INotificationsD
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async virtual Task<List<UserNotification>> GetListByNotificationIdssync(
IEnumerable<long> notificationIds,
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(x => notificationIds.Contains(x.NotificationId))
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async virtual Task<List<UserNotificationInfo>> GetNotificationsAsync(
Guid userId,
NotificationReadState? readState = null,

4
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs

@ -66,8 +66,10 @@ public interface INotificationStore
NotificationInfo notification,
CancellationToken cancellationToken = default);
Task DeleteNotificationAsync(
Task DeleteExpritionNotificationAsync(
Guid? tenantId,
int batchCount,
DateTime expritionTime,
CancellationToken cancellationToken = default);
Task InsertUserNotificationAsync(

4
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NullNotificationStore.cs

@ -46,8 +46,10 @@ public class NullNotificationStore : INotificationStore, ISingletonDependency
return Task.CompletedTask;
}
public Task DeleteNotificationAsync(
public Task DeleteExpritionNotificationAsync(
Guid? tenantId,
int batchCount,
DateTime expritionTime,
CancellationToken cancellationToken = default)
{
return Task.CompletedTask;

Loading…
Cancel
Save