From 5a6751f10b164e89c0f81fd6760c865fa734ab41 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 20 Jan 2021 18:31:51 +0800 Subject: [PATCH] Improve --- .../MongoDB/MongoBackgroundJobRepository.cs | 6 +++--- .../CmsKit/MongoDB/Contents/MongoContentRepository.cs | 2 +- .../MongoDB/MongoIdentitySecurityLogRepository.cs | 11 +++++++---- .../MongoDB/MongoPersistedGrantRepository.cs | 9 +++++---- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs index 88d28616a1..56d0bfaff1 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs @@ -24,15 +24,15 @@ namespace Volo.Abp.BackgroundJobs.MongoDB public virtual async Task> GetWaitingListAsync( int maxResultCount, - CancellationToken cancellationToken) + CancellationToken cancellationToken = default) { return await (await GetWaitingListQuery(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken)); } - protected virtual async Task> GetWaitingListQuery(int maxResultCount) + protected virtual async Task> GetWaitingListQuery(int maxResultCount, CancellationToken cancellationToken = default) { var now = Clock.Now; - return (await GetMongoQueryableAsync()) + return (await GetMongoQueryableAsync(cancellationToken)) .Where(t => !t.IsAbandoned && t.NextTryTime <= now) .OrderByDescending(t => t.Priority) .ThenBy(t => t.TryCount) diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs index f42b0890e7..1068c352d5 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs @@ -54,7 +54,7 @@ namespace Volo.CmsKit.MongoDB.Contents public async Task ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()).AnyAsync(x => + return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.EntityType == entityType && x.EntityId == entityId && x.TenantId == tenantId, diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs index cc926db139..1ac54cfc82 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs @@ -44,7 +44,8 @@ namespace Volo.Abp.Identity.MongoDB userId, userName, clientId, - correlationId + correlationId, + cancellationToken ); return await query.OrderBy(sorting ?? nameof(IdentitySecurityLog.CreationTime) + " desc") @@ -74,7 +75,8 @@ namespace Volo.Abp.Identity.MongoDB userId, userName, clientId, - correlationId + correlationId, + cancellationToken ); return await query.As>() @@ -98,9 +100,10 @@ namespace Volo.Abp.Identity.MongoDB Guid? userId = null, string userName = null, string clientId = null, - string correlationId = null) + string correlationId = null, + CancellationToken cancellationToken = default) { - return (await GetMongoQueryableAsync()) + return (await GetMongoQueryableAsync(cancellationToken)) .WhereIf(startTime.HasValue, securityLog => securityLog.CreationTime >= startTime.Value) .WhereIf(endTime.HasValue, securityLog => securityLog.CreationTime < endTime.Value.AddDays(1).Date) .WhereIf(!applicationName.IsNullOrWhiteSpace(), diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs index 2d4728a7e1..9dd4f24af6 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs @@ -21,7 +21,7 @@ namespace Volo.Abp.IdentityServer.MongoDB public async Task> GetListAsync(string subjectId, string sessionId, string clientId, string type, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await FilterAsync(subjectId, sessionId, clientId, type)) + return await (await FilterAsync(subjectId, sessionId, clientId, type, cancellationToken)) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -57,7 +57,7 @@ namespace Volo.Abp.IdentityServer.MongoDB string type = null, CancellationToken cancellationToken = default) { - var persistedGrants = await (await FilterAsync(subjectId, sessionId, clientId, type)) + var persistedGrants = await (await FilterAsync(subjectId, sessionId, clientId, type, cancellationToken)) .ToListAsync(GetCancellationToken(cancellationToken)); foreach (var persistedGrant in persistedGrants) @@ -86,9 +86,10 @@ namespace Volo.Abp.IdentityServer.MongoDB string subjectId, string sessionId, string clientId, - string type) + string type, + CancellationToken cancellationToken = default) { - return (await GetMongoQueryableAsync()) + return (await GetMongoQueryableAsync(cancellationToken)) .WhereIf>(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId) .WhereIf>(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId) .WhereIf>(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId)