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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with
35 additions and
6 deletions
-
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Domain/LINGYUN/Abp/Notifications/INotificationRepository.cs
-
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Domain/LINGYUN/Abp/Notifications/IUserNotificationRepository.cs
-
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Domain/LINGYUN/Abp/Notifications/NotificationStore.cs
-
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationRepository.cs
-
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreUserNotificationRepository.cs
-
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs
-
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NullNotificationStore.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); |
|
|
|
} |
|
|
|
|
|
|
|
@ -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 = "", |
|
|
|
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
@ -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)); |
|
|
|
|
|
|
|
@ -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, |
|
|
|
|
|
|
|
@ -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( |
|
|
|
|
|
|
|
@ -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; |
|
|
|
|