Browse Source
Optimize Clock.Now usage in user delegation repositories
pull/23563/head
maliming
1 year ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
2 changed files with
11 additions and
7 deletions
-
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserDelegationRepository.cs
-
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserDelegationRepository.cs
|
|
|
@ -31,22 +31,24 @@ public class EfCoreIdentityUserDelegationRepository : EfCoreRepository<IIdentity |
|
|
|
|
|
|
|
public virtual async Task<List<IdentityUserDelegation>> GetActiveDelegationsAsync(Guid targetUserId, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var now = Clock.Now; |
|
|
|
return await (await GetDbSetAsync()) |
|
|
|
.AsNoTracking() |
|
|
|
.Where(x => x.TargetUserId == targetUserId && |
|
|
|
x.StartTime <= Clock.Now && |
|
|
|
x.EndTime >= Clock.Now) |
|
|
|
x.StartTime <= now && |
|
|
|
x.EndTime >= now) |
|
|
|
.ToListAsync(cancellationToken: cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<IdentityUserDelegation> FindActiveDelegationByIdAsync(Guid id, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var now = Clock.Now; |
|
|
|
return await (await GetDbSetAsync()) |
|
|
|
.AsNoTracking() |
|
|
|
.FirstOrDefaultAsync(x => |
|
|
|
x.Id == id && |
|
|
|
x.StartTime <= Clock.Now && |
|
|
|
x.EndTime >= Clock.Now |
|
|
|
x.StartTime <= now && |
|
|
|
x.EndTime >= now |
|
|
|
, cancellationToken: GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -32,19 +32,21 @@ public class MongoIdentityUserDelegationRepository : MongoDbRepository<IAbpIdent |
|
|
|
|
|
|
|
public virtual async Task<List<IdentityUserDelegation>> GetActiveDelegationsAsync(Guid targetUserId, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var now = Clock.Now; |
|
|
|
return await (await GetQueryableAsync(cancellationToken)) |
|
|
|
.Where(x => x.TargetUserId == targetUserId) |
|
|
|
.Where(x => x.StartTime <= Clock.Now && x.EndTime >= Clock.Now) |
|
|
|
.Where(x => x.StartTime <= now && x.EndTime >= now) |
|
|
|
.ToListAsync(cancellationToken: cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<IdentityUserDelegation> FindActiveDelegationByIdAsync(Guid id, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var now = Clock.Now; |
|
|
|
return await (await GetQueryableAsync(cancellationToken)) |
|
|
|
.FirstOrDefaultAsync(x => |
|
|
|
x.Id == id && |
|
|
|
x.StartTime <= Clock.Now && |
|
|
|
x.EndTime >= Clock.Now |
|
|
|
x.StartTime <= now && |
|
|
|
x.EndTime >= now |
|
|
|
, cancellationToken: GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
} |
|
|
|
|