Browse Source

Update `GetPruneListAsync` of `IOpenIddictAuthorizationRepository`

pull/15400/head
maliming 4 years ago
parent
commit
1b9a2878c6
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 17
      modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs
  2. 18
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs

17
modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs

@ -8,6 +8,7 @@ using OpenIddict.Abstractions;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.OpenIddict.EntityFrameworkCore;
using Volo.Abp.OpenIddict.Tokens;
namespace Volo.Abp.OpenIddict.Authorizations;
@ -81,13 +82,13 @@ public class EfCoreOpenIddictAuthorizationRepository : EfCoreRepository<IOpenIdd
public virtual async Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default)
{
var tokenQueryable = (await GetDbContextAsync()).Tokens.AsQueryable();
return await (await GetDbSetAsync())
.Where(x => x.CreationDate < date)
.Where(x => x.Status != OpenIddictConstants.Statuses.Valid ||
(x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && tokenQueryable.Any(t => t.AuthorizationId == x.Id)))
.OrderBy(x => x.Id)
.Take(count)
.ToListAsync(GetCancellationToken(cancellationToken));
return await (from authorization in (await GetQueryableAsync())
join token in (await GetDbContextAsync()).Set<OpenIddictToken>()
on authorization.Id equals token.AuthorizationId into authorizationTokens
from authorizationToken in authorizationTokens.DefaultIfEmpty()
where authorization.CreationDate < date
where authorization.Status != OpenIddictConstants.Statuses.Valid ||
(authorization.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && authorizationToken == null)
select authorization).ToListAsync(cancellationToken: cancellationToken);
}
}

18
modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs

@ -67,16 +67,16 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository<OpenIddi
public virtual async Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default)
{
var tokenQueryable = await GetMongoQueryableAsync<OpenIddictToken>(GetCancellationToken(cancellationToken));
var authorizations = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
var tokens = await (await GetMongoQueryableAsync<OpenIddictToken>(cancellationToken))
.Where(x => x.AuthorizationId != null)
.Select(x => x.AuthorizationId.Value)
.ToListAsync(GetCancellationToken(cancellationToken));
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.CreationDate < date)
.Where(x => x.Status != OpenIddictConstants.Statuses.Valid ||
(x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc))
.OrderBy(x => x.Id)
.Take(count)
.ToListAsync(GetCancellationToken(cancellationToken));
return authorizations.Where(x => tokenQueryable.Any(t => t.AuthorizationId == x.Id)).ToList();
(x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && !tokens.Contains(x.Id)))
.ToListAsync(cancellationToken: cancellationToken);
}
}

Loading…
Cancel
Save