Browse Source

Merge pull request #1275 from colinin/remove-user-expired-notifications

fix: Delete users expired notifications
pull/1284/head
yx lin 8 months ago
committed by GitHub
parent
commit
d508c447c4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  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;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -13,5 +14,6 @@ public interface INotificationRepository : IBasicRepository<Notification, long>
Task<List<Notification>> GetExpritionAsync( Task<List<Notification>> GetExpritionAsync(
int batchCount, int batchCount,
DateTime expritionTime,
CancellationToken cancellationToken = default); 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, int maxResultCount = 10,
CancellationToken cancellationToken = default); CancellationToken cancellationToken = default);
Task<List<UserNotification>> GetListByNotificationIdssync(
IEnumerable<long> notificationIds,
CancellationToken cancellationToken = default);
Task<int> GetCountAsync( Task<int> GetCountAsync(
Guid userId, Guid userId,
string filter = "", 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, int batchCount,
DateTime expritionTime,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
using (var unitOfWork = _unitOfWorkManager.Begin()) 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 _notificationRepository.DeleteManyAsync(notitications);
// 清理用户通知
await _userNotificationRepository.DeleteManyAsync(userNotitications);
await unitOfWork.CompleteAsync(cancellationToken); 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( public async Task<List<Notification>> GetExpritionAsync(
int batchCount, int batchCount,
DateTime expritionTime,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.Where(x => x.ExpirationTime < DateTime.Now) .Where(x => x.ExpirationTime < expritionTime)
.OrderBy(x => x.ExpirationTime) .OrderBy(x => x.ExpirationTime)
.Take(batchCount) .Take(batchCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .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)); .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( public async virtual Task<List<UserNotificationInfo>> GetNotificationsAsync(
Guid userId, Guid userId,
NotificationReadState? readState = null, 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, NotificationInfo notification,
CancellationToken cancellationToken = default); CancellationToken cancellationToken = default);
Task DeleteNotificationAsync( Task DeleteExpritionNotificationAsync(
Guid? tenantId,
int batchCount, int batchCount,
DateTime expritionTime,
CancellationToken cancellationToken = default); CancellationToken cancellationToken = default);
Task InsertUserNotificationAsync( 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; return Task.CompletedTask;
} }
public Task DeleteNotificationAsync( public Task DeleteExpritionNotificationAsync(
Guid? tenantId,
int batchCount, int batchCount,
DateTime expritionTime,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return Task.CompletedTask; return Task.CompletedTask;

Loading…
Cancel
Save