Browse Source

Optimize Clock.Now usage in user delegation repositories

pull/23563/head
maliming 1 year ago
parent
commit
8a15eee94f
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 10
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserDelegationRepository.cs
  2. 8
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserDelegationRepository.cs

10
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserDelegationRepository.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));
}
}

8
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserDelegationRepository.cs

@ -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));
}
}

Loading…
Cancel
Save