From 19e4589c76c50d9602d59eba6862f00a33bde850 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 1 Dec 2022 14:41:44 +0800 Subject: [PATCH 1/3] Use EF Core 7.0 bulk update/delete operations. Resolve #14892 --- .../MySQLInboxConfigExtensions.cs | 12 ----- .../MySQLOutboxConfigExtensions.cs | 12 ----- .../IOracleDbContextEventInbox.cs | 7 --- .../IOracleDbContextEventOutbox.cs | 6 --- .../OracleDbContextEventInbox.cs | 47 ------------------- .../OracleDbContextEventOutbox.cs | 30 ------------ .../OracleInboxConfigExtensions.cs | 12 ----- .../OracleOutboxConfigExtensions.cs | 12 ----- ...bpEntityFrameworkCoreOracleDevartModule.cs | 4 -- .../IOracleDbContextEventInbox.cs | 7 --- .../IOracleDbContextEventOutbox.cs | 6 --- .../OracleDbContextEventInbox.cs | 47 ------------------- .../OracleDbContextEventOutbox.cs | 30 ------------ .../OracleInboxConfigExtensions.cs | 12 ----- .../OracleOutboxConfigExtensions.cs | 12 ----- .../AbpEntityFrameworkCoreOracleModule.cs | 4 -- .../IPostgreSqlDbContextEventInbox.cs | 7 --- .../IPostgreSqlDbContextEventOutbox.cs | 6 --- .../PostgreSqlDbContextEventInbox.cs | 42 ----------------- .../PostgreSqlDbContextEventOutbox.cs | 24 ---------- .../PostgreSqlInboxConfigExtensions.cs | 12 ----- .../PostgreSqlOutboxConfigExtensions.cs | 12 ----- .../AbpEntityFrameworkCorePostgreSqlModule.cs | 7 +-- .../SqlServerInboxConfigExtensions.cs | 12 ----- .../SqlServerOutboxConfigExtensions.cs | 12 ----- .../SqliteInboxConfigExtensions.cs | 12 ----- .../SqliteOutboxConfigExtensions.cs | 12 ----- .../AbpEntityFrameworkCoreModule.cs | 3 -- .../DistributedEvents/DbContextEventInbox.cs | 17 ++----- .../DistributedEvents/DbContextEventOutbox.cs | 16 ++----- .../ISqlRawDbContextEventInbox.cs | 6 --- .../ISqlRawDbContextEventOutbox.cs | 6 --- .../SqlRawDbContextEventInbox.cs | 42 ----------------- .../SqlRawDbContextEventOutbox.cs | 25 ---------- .../Devices/IDeviceFlowCodesRepository.cs | 5 ++ .../Grants/IPersistentGrantRepository.cs | 5 ++ .../Tokens/TokenCleanupOptions.cs | 5 +- .../Tokens/TokenCleanupService.cs | 28 ++--------- .../Devices/DeviceFlowCodesRepository.cs | 5 ++ .../Grants/PersistentGrantRepository.cs | 5 ++ .../MongoDB/MongoDeviceFlowCodesRepository.cs | 5 ++ .../MongoDB/MongoPersistentGrantRepository.cs | 5 ++ .../AbpOpenIddictAuthorizationStore.cs | 24 +++------- .../IOpenIddictAuthorizationRepository.cs | 2 + .../Tokens/AbpOpenIddictTokenStore.cs | 24 +++------- .../Tokens/IOpenIddictTokenRepository.cs | 2 + ...EfCoreOpenIddictAuthorizationRepository.cs | 13 ++++- .../Tokens/EfCoreOpenIddictTokenRepository.cs | 18 ++++++- .../MongoOpenIddictAuthorizationRepository.cs | 18 +++++-- .../Tokens/MongoOpenIddictTokenRepository.cs | 41 +++++++++++----- 50 files changed, 132 insertions(+), 606 deletions(-) delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/DistributedEvents/MySQLInboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/DistributedEvents/MySQLOutboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventInbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventOutbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventInbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventOutbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleInboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleOutboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventInbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventOutbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventInbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventOutbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleInboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleOutboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/IPostgreSqlDbContextEventInbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/IPostgreSqlDbContextEventOutbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlDbContextEventInbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlDbContextEventOutbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlInboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlOutboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.SqlServer/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlServerInboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.SqlServer/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlServerOutboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqliteInboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqliteOutboxConfigExtensions.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/ISqlRawDbContextEventInbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/ISqlRawDbContextEventOutbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlRawDbContextEventInbox.cs delete mode 100644 framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlRawDbContextEventOutbox.cs diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/DistributedEvents/MySQLInboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/DistributedEvents/MySQLInboxConfigExtensions.cs deleted file mode 100644 index 5579c9f90f..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/DistributedEvents/MySQLInboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class MySQLInboxConfigExtensions -{ - public static void UseMySQL(this InboxConfig outboxConfig) - where TDbContext : IHasEventInbox - { - outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventInbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/DistributedEvents/MySQLOutboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/DistributedEvents/MySQLOutboxConfigExtensions.cs deleted file mode 100644 index 97d1d321cb..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/DistributedEvents/MySQLOutboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class MySQLOutboxConfigExtensions -{ - public static void UseMySQL(this OutboxConfig outboxConfig) - where TDbContext : IHasEventOutbox - { - outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventOutbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventInbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventInbox.cs deleted file mode 100644 index 63ba8379e0..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventInbox.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public interface IOracleDbContextEventInbox : IDbContextEventInbox - where TDbContext : IHasEventInbox -{ - -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventOutbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventOutbox.cs deleted file mode 100644 index 32aa01be86..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventOutbox.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public interface IOracleDbContextEventOutbox : IDbContextEventOutbox - where TDbContext : IHasEventOutbox -{ -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventInbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventInbox.cs deleted file mode 100644 index 93d740dc21..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventInbox.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Options; -using Volo.Abp.EventBus.Distributed; -using Volo.Abp.Timing; -using Volo.Abp.Uow; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public class OracleDbContextEventInbox : DbContextEventInbox, IOracleDbContextEventInbox - where TDbContext : IHasEventInbox -{ - public OracleDbContextEventInbox( - IDbContextProvider dbContextProvider, - IClock clock, - IOptions eventBusBoxesOptions) - : base(dbContextProvider, clock, eventBusBoxesOptions) - { - } - - [UnitOfWork] - public override async Task MarkAsProcessedAsync(Guid id) - { - var dbContext = await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); - - var sql = $"UPDATE \"{tableName}\" SET \"Processed\" = '1', \"ProcessedTime\" = TO_DATE('{Clock.Now}', 'yyyy-mm-dd hh24:mi:ss') WHERE \"Id\" = HEXTORAW('{GuidToOracleType(id)}')"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } - - [UnitOfWork] - public override async Task DeleteOldEventsAsync() - { - var dbContext = await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); - var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents; - - var sql = $"DELETE FROM \"{tableName}\" WHERE \"Processed\" = '1' AND \"CreationTime\" < TO_DATE('{timeToKeepEvents}', 'yyyy-mm-dd hh24:mi:ss')"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } - - protected virtual string GuidToOracleType(Guid id) - { - return BitConverter.ToString(id.ToByteArray()).Replace("-", "").ToUpper(); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventOutbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventOutbox.cs deleted file mode 100644 index 0a2286bbb7..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventOutbox.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Volo.Abp.Uow; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public class OracleDbContextEventOutbox : DbContextEventOutbox, IOracleDbContextEventOutbox - where TDbContext : IHasEventOutbox -{ - public OracleDbContextEventOutbox(IDbContextProvider dbContextProvider) - : base(dbContextProvider) - { - } - - [UnitOfWork] - public override async Task DeleteAsync(Guid id) - { - var dbContext = (IHasEventOutbox)await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.OutgoingEvents.EntityType.GetSchemaQualifiedTableName(); - - var sql = $"DELETE FROM \"{tableName}\" WHERE \"Id\" = HEXTORAW('{GuidToOracleType(id)}')"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } - - protected virtual string GuidToOracleType(Guid id) - { - return BitConverter.ToString(id.ToByteArray()).Replace("-", "").ToUpper(); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleInboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleInboxConfigExtensions.cs deleted file mode 100644 index a6cd040103..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleInboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class OracleInboxConfigExtensions -{ - public static void UseOracle(this InboxConfig outboxConfig) - where TDbContext : IHasEventInbox - { - outboxConfig.ImplementationType = typeof(IOracleDbContextEventInbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleOutboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleOutboxConfigExtensions.cs deleted file mode 100644 index 07e5dc004f..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleOutboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class OracleOutboxConfigExtensions -{ - public static void UseOracle(this OutboxConfig outboxConfig) - where TDbContext : IHasEventOutbox - { - outboxConfig.ImplementationType = typeof(IOracleDbContextEventOutbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/Oracle/Devart/AbpEntityFrameworkCoreOracleDevartModule.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/Oracle/Devart/AbpEntityFrameworkCoreOracleDevartModule.cs index 25b0b088d7..3b4129b272 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/Oracle/Devart/AbpEntityFrameworkCoreOracleDevartModule.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle.Devart/Volo/Abp/EntityFrameworkCore/Oracle/Devart/AbpEntityFrameworkCoreOracleDevartModule.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.EntityFrameworkCore.DistributedEvents; using Volo.Abp.Guids; using Volo.Abp.Modularity; @@ -19,8 +18,5 @@ public class AbpEntityFrameworkCoreOracleDevartModule : AbpModule options.DefaultSequentialGuidType = SequentialGuidType.SequentialAsBinary; } }); - - context.Services.AddTransient(typeof(IOracleDbContextEventOutbox<>), typeof(OracleDbContextEventOutbox<>)); - context.Services.AddTransient(typeof(IOracleDbContextEventInbox<>), typeof(OracleDbContextEventInbox<>)); } } diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventInbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventInbox.cs deleted file mode 100644 index 63ba8379e0..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventInbox.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public interface IOracleDbContextEventInbox : IDbContextEventInbox - where TDbContext : IHasEventInbox -{ - -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventOutbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventOutbox.cs deleted file mode 100644 index 32aa01be86..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventOutbox.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public interface IOracleDbContextEventOutbox : IDbContextEventOutbox - where TDbContext : IHasEventOutbox -{ -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventInbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventInbox.cs deleted file mode 100644 index 93d740dc21..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventInbox.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Options; -using Volo.Abp.EventBus.Distributed; -using Volo.Abp.Timing; -using Volo.Abp.Uow; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public class OracleDbContextEventInbox : DbContextEventInbox, IOracleDbContextEventInbox - where TDbContext : IHasEventInbox -{ - public OracleDbContextEventInbox( - IDbContextProvider dbContextProvider, - IClock clock, - IOptions eventBusBoxesOptions) - : base(dbContextProvider, clock, eventBusBoxesOptions) - { - } - - [UnitOfWork] - public override async Task MarkAsProcessedAsync(Guid id) - { - var dbContext = await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); - - var sql = $"UPDATE \"{tableName}\" SET \"Processed\" = '1', \"ProcessedTime\" = TO_DATE('{Clock.Now}', 'yyyy-mm-dd hh24:mi:ss') WHERE \"Id\" = HEXTORAW('{GuidToOracleType(id)}')"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } - - [UnitOfWork] - public override async Task DeleteOldEventsAsync() - { - var dbContext = await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); - var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents; - - var sql = $"DELETE FROM \"{tableName}\" WHERE \"Processed\" = '1' AND \"CreationTime\" < TO_DATE('{timeToKeepEvents}', 'yyyy-mm-dd hh24:mi:ss')"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } - - protected virtual string GuidToOracleType(Guid id) - { - return BitConverter.ToString(id.ToByteArray()).Replace("-", "").ToUpper(); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventOutbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventOutbox.cs deleted file mode 100644 index 0a2286bbb7..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventOutbox.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Volo.Abp.Uow; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public class OracleDbContextEventOutbox : DbContextEventOutbox, IOracleDbContextEventOutbox - where TDbContext : IHasEventOutbox -{ - public OracleDbContextEventOutbox(IDbContextProvider dbContextProvider) - : base(dbContextProvider) - { - } - - [UnitOfWork] - public override async Task DeleteAsync(Guid id) - { - var dbContext = (IHasEventOutbox)await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.OutgoingEvents.EntityType.GetSchemaQualifiedTableName(); - - var sql = $"DELETE FROM \"{tableName}\" WHERE \"Id\" = HEXTORAW('{GuidToOracleType(id)}')"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } - - protected virtual string GuidToOracleType(Guid id) - { - return BitConverter.ToString(id.ToByteArray()).Replace("-", "").ToUpper(); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleInboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleInboxConfigExtensions.cs deleted file mode 100644 index a6cd040103..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleInboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class OracleInboxConfigExtensions -{ - public static void UseOracle(this InboxConfig outboxConfig) - where TDbContext : IHasEventInbox - { - outboxConfig.ImplementationType = typeof(IOracleDbContextEventInbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleOutboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleOutboxConfigExtensions.cs deleted file mode 100644 index 07e5dc004f..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleOutboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class OracleOutboxConfigExtensions -{ - public static void UseOracle(this OutboxConfig outboxConfig) - where TDbContext : IHasEventOutbox - { - outboxConfig.ImplementationType = typeof(IOracleDbContextEventOutbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/Oracle/AbpEntityFrameworkCoreOracleModule.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/Oracle/AbpEntityFrameworkCoreOracleModule.cs index 4347d9446a..54627a90c0 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/Oracle/AbpEntityFrameworkCoreOracleModule.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo/Abp/EntityFrameworkCore/Oracle/AbpEntityFrameworkCoreOracleModule.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.EntityFrameworkCore.DistributedEvents; using Volo.Abp.Guids; using Volo.Abp.Modularity; @@ -17,8 +16,5 @@ public class AbpEntityFrameworkCoreOracleModule : AbpModule options.DefaultSequentialGuidType = SequentialGuidType.SequentialAsBinary; } }); - - context.Services.AddTransient(typeof(IOracleDbContextEventOutbox<>), typeof(OracleDbContextEventOutbox<>)); - context.Services.AddTransient(typeof(IOracleDbContextEventInbox<>), typeof(OracleDbContextEventInbox<>)); } } diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/IPostgreSqlDbContextEventInbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/IPostgreSqlDbContextEventInbox.cs deleted file mode 100644 index b81eb2bff1..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/IPostgreSqlDbContextEventInbox.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public interface IPostgreSqlDbContextEventInbox : IDbContextEventInbox - where TDbContext : IHasEventInbox -{ - -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/IPostgreSqlDbContextEventOutbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/IPostgreSqlDbContextEventOutbox.cs deleted file mode 100644 index e21632dc4e..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/IPostgreSqlDbContextEventOutbox.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public interface IPostgreSqlDbContextEventOutbox : IDbContextEventOutbox - where TDbContext : IHasEventOutbox -{ -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlDbContextEventInbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlDbContextEventInbox.cs deleted file mode 100644 index 054ed78ee7..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlDbContextEventInbox.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Options; -using Volo.Abp.EventBus.Distributed; -using Volo.Abp.Timing; -using Volo.Abp.Uow; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public class PostgreSqlDbContextEventInbox : DbContextEventInbox, IPostgreSqlDbContextEventInbox - where TDbContext : IHasEventInbox -{ - public PostgreSqlDbContextEventInbox( - IDbContextProvider dbContextProvider, - IClock clock, - IOptions eventBusBoxesOptions) - : base(dbContextProvider, clock, eventBusBoxesOptions) - { - } - - [UnitOfWork] - public override async Task MarkAsProcessedAsync(Guid id) - { - var dbContext = await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); - - var sql = $"UPDATE \"{tableName}\" SET \"Processed\" = '1', \"ProcessedTime\" = '{Clock.Now}' WHERE \"Id\" = '{id}'"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } - - [UnitOfWork] - public override async Task DeleteOldEventsAsync() - { - var dbContext = await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); - var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents; - - var sql = $"DELETE FROM \"{tableName}\" WHERE \"Processed\" = '1' AND \"CreationTime\" < '{timeToKeepEvents}'"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlDbContextEventOutbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlDbContextEventOutbox.cs deleted file mode 100644 index 7c5ef12fa7..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlDbContextEventOutbox.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Volo.Abp.Uow; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public class PostgreSqlDbContextEventOutbox : DbContextEventOutbox, IPostgreSqlDbContextEventOutbox - where TDbContext : IHasEventOutbox -{ - public PostgreSqlDbContextEventOutbox(IDbContextProvider dbContextProvider) : base(dbContextProvider) - { - } - - [UnitOfWork] - public async override Task DeleteAsync(Guid id) - { - var dbContext = (IHasEventOutbox)await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.OutgoingEvents.EntityType.GetSchemaQualifiedTableName(); - - var sql = $"DELETE FROM \"{tableName}\" WHERE \"Id\" = '{id}'"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlInboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlInboxConfigExtensions.cs deleted file mode 100644 index 57d50f24eb..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlInboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class PostgreSqlInboxConfigExtensions -{ - public static void UseNpgsql(this InboxConfig outboxConfig) - where TDbContext : IHasEventInbox - { - outboxConfig.ImplementationType = typeof(IPostgreSqlDbContextEventInbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlOutboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlOutboxConfigExtensions.cs deleted file mode 100644 index 3d88398068..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/DistributedEvents/PostgreSqlOutboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class PostgreSqlOutboxConfigExtensions -{ - public static void UseNpgsql(this OutboxConfig outboxConfig) - where TDbContext : IHasEventOutbox - { - outboxConfig.ImplementationType = typeof(IPostgreSqlDbContextEventOutbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs index 8fffb8359c..2b679cccef 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs @@ -1,6 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.EntityFrameworkCore.DistributedEvents; -using Volo.Abp.Guids; +using Volo.Abp.Guids; using Volo.Abp.Modularity; namespace Volo.Abp.EntityFrameworkCore.PostgreSql; @@ -19,8 +17,5 @@ public class AbpEntityFrameworkCorePostgreSqlModule : AbpModule options.DefaultSequentialGuidType = SequentialGuidType.SequentialAsString; } }); - - context.Services.AddTransient(typeof(IPostgreSqlDbContextEventOutbox<>), typeof(PostgreSqlDbContextEventOutbox<>)); - context.Services.AddTransient(typeof(IPostgreSqlDbContextEventInbox<>), typeof(PostgreSqlDbContextEventInbox<>)); } } diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.SqlServer/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlServerInboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.SqlServer/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlServerInboxConfigExtensions.cs deleted file mode 100644 index e5ac47a18f..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.SqlServer/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlServerInboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class SqlServerInboxConfigExtensions -{ - public static void UseSqlServer(this InboxConfig outboxConfig) - where TDbContext : IHasEventInbox - { - outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventInbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.SqlServer/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlServerOutboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.SqlServer/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlServerOutboxConfigExtensions.cs deleted file mode 100644 index e69005e6c9..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.SqlServer/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlServerOutboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class SqlServerOutboxConfigExtensions -{ - public static void UseSqlServer(this OutboxConfig outboxConfig) - where TDbContext : IHasEventOutbox - { - outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventOutbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqliteInboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqliteInboxConfigExtensions.cs deleted file mode 100644 index 317ca6fabc..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqliteInboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class SqliteInboxConfigExtensions -{ - public static void UseSqlite(this InboxConfig outboxConfig) - where TDbContext : IHasEventInbox - { - outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventInbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqliteOutboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqliteOutboxConfigExtensions.cs deleted file mode 100644 index e533b94b92..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqliteOutboxConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.EventBus.Distributed; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public static class SqliteOutboxConfigExtensions -{ - public static void UseSqlite(this OutboxConfig outboxConfig) - where TDbContext : IHasEventOutbox - { - outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventOutbox); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs index 7b58a91fc7..c98ef478d4 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs @@ -28,8 +28,5 @@ public class AbpEntityFrameworkCoreModule : AbpModule context.Services.TryAddTransient(typeof(IDbContextProvider<>), typeof(UnitOfWorkDbContextProvider<>)); context.Services.AddTransient(typeof(IDbContextEventOutbox<>), typeof(DbContextEventOutbox<>)); context.Services.AddTransient(typeof(IDbContextEventInbox<>), typeof(DbContextEventInbox<>)); - - context.Services.AddTransient(typeof(ISqlRawDbContextEventOutbox<>), typeof(SqlRawDbContextEventOutbox<>)); - context.Services.AddTransient(typeof(ISqlRawDbContextEventInbox<>), typeof(SqlRawDbContextEventInbox<>)); } } diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/DbContextEventInbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/DbContextEventInbox.cs index 1035716491..f5953ea3b1 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/DbContextEventInbox.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/DbContextEventInbox.cs @@ -32,10 +32,7 @@ public class DbContextEventInbox : IDbContextEventInbox public virtual async Task EnqueueAsync(IncomingEventInfo incomingEvent) { var dbContext = await DbContextProvider.GetDbContextAsync(); - - dbContext.IncomingEvents.Add( - new IncomingEventRecord(incomingEvent) - ); + dbContext.IncomingEvents.Add(new IncomingEventRecord(incomingEvent)); } [UnitOfWork] @@ -60,11 +57,8 @@ public class DbContextEventInbox : IDbContextEventInbox public virtual async Task MarkAsProcessedAsync(Guid id) { var dbContext = await DbContextProvider.GetDbContextAsync(); - var incomingEvent = await dbContext.IncomingEvents.FindAsync(id); - if (incomingEvent != null) - { - incomingEvent.MarkAsProcessed(Clock.Now); - } + await dbContext.IncomingEvents.Where(x => x.Id == id).ExecuteUpdateAsync(x => + x.SetProperty(p => p.Processed, _ => true).SetProperty(p => p.ProcessedTime, _ => Clock.Now)); } [UnitOfWork] @@ -79,9 +73,8 @@ public class DbContextEventInbox : IDbContextEventInbox { var dbContext = await DbContextProvider.GetDbContextAsync(); var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents; - var oldEvents = await dbContext.IncomingEvents + await dbContext.IncomingEvents .Where(x => x.Processed && x.CreationTime < timeToKeepEvents) - .ToListAsync(); - dbContext.IncomingEvents.RemoveRange(oldEvents); + .ExecuteDeleteAsync(); } } diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/DbContextEventOutbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/DbContextEventOutbox.cs index c2816ea4c3..fecfd1e8ce 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/DbContextEventOutbox.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/DbContextEventOutbox.cs @@ -24,9 +24,7 @@ public class DbContextEventOutbox : IDbContextEventOutbox : IDbContextEventOutbox x.Id == id).ExecuteDeleteAsync(); } [UnitOfWork] public virtual async Task DeleteManyAsync(IEnumerable ids) { var dbContext = (IHasEventOutbox)await DbContextProvider.GetDbContextAsync(); - var outgoingEvents = await dbContext.OutgoingEvents.Where(x => ids.Contains(x.Id)).ToListAsync(); - if (outgoingEvents.Any()) - { - dbContext.RemoveRange(outgoingEvents); - } + await dbContext.OutgoingEvents.Where(x => ids.Contains(x.Id)).ExecuteDeleteAsync(); } } diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/ISqlRawDbContextEventInbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/ISqlRawDbContextEventInbox.cs deleted file mode 100644 index 73d324eedc..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/ISqlRawDbContextEventInbox.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public interface ISqlRawDbContextEventInbox : IDbContextEventInbox - where TDbContext : IHasEventInbox -{ -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/ISqlRawDbContextEventOutbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/ISqlRawDbContextEventOutbox.cs deleted file mode 100644 index 7a6608146a..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/ISqlRawDbContextEventOutbox.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public interface ISqlRawDbContextEventOutbox : IDbContextEventOutbox - where TDbContext : IHasEventOutbox -{ -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlRawDbContextEventInbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlRawDbContextEventInbox.cs deleted file mode 100644 index 0aa99e7df7..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlRawDbContextEventInbox.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Options; -using Volo.Abp.EventBus.Distributed; -using Volo.Abp.Timing; -using Volo.Abp.Uow; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public class SqlRawDbContextEventInbox : DbContextEventInbox, ISqlRawDbContextEventInbox - where TDbContext : IHasEventInbox -{ - public SqlRawDbContextEventInbox( - IDbContextProvider dbContextProvider, - IClock clock, - IOptions eventBusBoxesOptions) - : base(dbContextProvider, clock, eventBusBoxesOptions) - { - } - - [UnitOfWork] - public override async Task MarkAsProcessedAsync(Guid id) - { - var dbContext = await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); - - var sql = $"UPDATE {tableName} SET Processed = '1', ProcessedTime = '{Clock.Now}' WHERE Id = '{id.ToString().ToUpper()}'"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } - - [UnitOfWork] - public override async Task DeleteOldEventsAsync() - { - var dbContext = await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); - var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents; - - var sql = $"DELETE FROM {tableName} WHERE Processed = '1' AND CreationTime < '{timeToKeepEvents}'"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } -} diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlRawDbContextEventOutbox.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlRawDbContextEventOutbox.cs deleted file mode 100644 index 4c3717d80d..0000000000 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/SqlRawDbContextEventOutbox.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Volo.Abp.Uow; - -namespace Volo.Abp.EntityFrameworkCore.DistributedEvents; - -public class SqlRawDbContextEventOutbox : DbContextEventOutbox, ISqlRawDbContextEventOutbox - where TDbContext : IHasEventOutbox -{ - public SqlRawDbContextEventOutbox(IDbContextProvider dbContextProvider) - : base(dbContextProvider) - { - } - - [UnitOfWork] - public override async Task DeleteAsync(Guid id) - { - var dbContext = (IHasEventOutbox)await DbContextProvider.GetDbContextAsync(); - var tableName = dbContext.OutgoingEvents.EntityType.GetSchemaQualifiedTableName(); - - var sql = $"DELETE FROM {tableName} WHERE Id = '{id.ToString().ToUpper()}'"; - await dbContext.Database.ExecuteSqlRawAsync(sql); - } -} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/IDeviceFlowCodesRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/IDeviceFlowCodesRepository.cs index 64f66fd6fe..26be5b7f7f 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/IDeviceFlowCodesRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/IDeviceFlowCodesRepository.cs @@ -23,4 +23,9 @@ public interface IDeviceFlowCodesRepository : IBasicRepository /// Default value: 100. /// + [Obsolete("This option will be removed in future versions.")] public int CleanupBatchSize { get; set; } = 100; /// @@ -22,6 +24,7 @@ public class TokenCleanupOptions /// /// Default value: 10. /// + /// [Obsolete("This option will be removed in future versions.")] public int CleanupLoopCount { get; set; } = 10; /// diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupService.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupService.cs index 98384a448c..155eb5e4ab 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupService.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupService.cs @@ -24,42 +24,20 @@ public class TokenCleanupService : ITransientDependency Options = options.Value; } + [UnitOfWork] public virtual async Task CleanAsync() { await RemoveGrantsAsync(); await RemoveDeviceCodesAsync(); } - [UnitOfWork] protected virtual async Task RemoveGrantsAsync() { - for (var i = 0; i < Options.CleanupLoopCount; i++) - { - var persistentGrants = await PersistentGrantRepository.GetListByExpirationAsync(DateTime.UtcNow, Options.CleanupBatchSize); - - await PersistentGrantRepository.DeleteManyAsync(persistentGrants); - - //No need to continue to query if it gets more than max items. - if (persistentGrants.Count < Options.CleanupBatchSize) - { - break; - } - } + await PersistentGrantRepository.DeleteExpirationAsync(DateTime.UtcNow); } protected virtual async Task RemoveDeviceCodesAsync() { - for (var i = 0; i < Options.CleanupLoopCount; i++) - { - var deviceFlowCodeses = await DeviceFlowCodesRepository.GetListByExpirationAsync(DateTime.UtcNow, Options.CleanupBatchSize); - - await DeviceFlowCodesRepository.DeleteManyAsync(deviceFlowCodeses); - - //No need to continue to query if it gets more than max items. - if (deviceFlowCodeses.Count < Options.CleanupBatchSize) - { - break; - } - } + await DeviceFlowCodesRepository.DeleteExpirationAsync(DateTime.UtcNow); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs index e9da122854..4548a2efeb 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs @@ -46,4 +46,9 @@ public class DeviceFlowCodesRepository : EfCoreRepository x.Expiration != null && x.Expiration < maxExpirationDate, cancellationToken); + } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistentGrantRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistentGrantRepository.cs index c0417eeda6..394b9c58ec 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistentGrantRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistentGrantRepository.cs @@ -55,6 +55,11 @@ public class PersistentGrantRepository : EfCoreRepository x.Expiration != null && x.Expiration < maxExpirationDate, cancellationToken); + } + public async Task DeleteAsync( string subjectId = null, string sessionId = null, diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs index 1b7e9519ae..921225a5ae 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs @@ -48,4 +48,9 @@ public class MongoDeviceFlowCodesRepository : .Take(maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } + + public virtual async Task DeleteExpirationAsync(DateTime maxExpirationDate, CancellationToken cancellationToken = default) + { + await DeleteDirectAsync(x => x.Expiration != null && x.Expiration < maxExpirationDate, cancellationToken: cancellationToken); + } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs index 8836e6d53e..a4651def23 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs @@ -50,6 +50,11 @@ public class MongoPersistentGrantRepository : MongoDbRepository x.Expiration != null && x.Expiration < maxExpirationDate, cancellationToken: cancellationToken); + } + public async Task DeleteAsync( string subjectId = null, string sessionId = null, diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs index 1abe7d774b..ca69914152 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs @@ -47,7 +47,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default); Task> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default); + + Task PruneAsync(DateTime date, CancellationToken cancellationToken = default); } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs index c8b80831a9..e95165a914 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs @@ -47,7 +47,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default); Task> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default); + + Task PruneAsync(DateTime date, CancellationToken cancellationToken = default); } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs index e9b4c4b3fb..54bc1a642b 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs @@ -85,9 +85,20 @@ public class EfCoreOpenIddictAuthorizationRepository : EfCoreRepository x.CreationDate < date) .Where(x => x.Status != OpenIddictConstants.Statuses.Valid || - (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && tokenQueryable.Any(t => t.AuthorizationId == x.Id))) + (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && + !tokenQueryable.Any(t => t.AuthorizationId == x.Id))) .OrderBy(x => x.Id) .Take(count) .ToListAsync(GetCancellationToken(cancellationToken)); } + + public virtual async Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) + { + var tokenQueryable = (await GetDbContextAsync()).Tokens.AsQueryable(); + await DeleteDirectAsync(x => x.CreationDate < date && + x.Status != OpenIddictConstants.Statuses.Valid || + (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && + !tokenQueryable.Any(t => t.AuthorizationId == x.Id)), + cancellationToken: cancellationToken); + } } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs index 01dd8fbc7f..ffdea1518a 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs @@ -87,7 +87,7 @@ public class EfCoreOpenIddictTokenRepository : EfCoreRepository> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default) + public virtual async Task> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default) { return await (from token in await GetQueryableAsync() join authorization in (await GetDbContextAsync()).Set().AsQueryable() @@ -102,4 +102,20 @@ public class EfCoreOpenIddictTokenRepository : EfCoreRepository().AsQueryable() + on token.AuthorizationId equals authorization.Id into ta + from a in ta + where token.CreationDate < date + where (token.Status != OpenIddictConstants.Statuses.Inactive && + token.Status != OpenIddictConstants.Statuses.Valid) || + (a != null && a.Status != OpenIddictConstants.Statuses.Valid) || + token.ExpirationDate < DateTime.UtcNow + orderby token.Id + select token) + .ExecuteDeleteAsync(GetCancellationToken(cancellationToken)); + } } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs index fe0042e54c..a9de4e7949 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs @@ -68,15 +68,23 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default) { var tokenQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)); - - var authorizations = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) .Where(x => x.CreationDate < date) .Where(x => x.Status != OpenIddictConstants.Statuses.Valid || - (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc)) + (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && + !tokenQueryable.Any(t => t.AuthorizationId == x.Id))) .OrderBy(x => x.Id) .Take(count) .ToListAsync(GetCancellationToken(cancellationToken)); - - return authorizations.Where(x => tokenQueryable.Any(t => t.AuthorizationId == x.Id)).ToList(); + } + + public virtual async Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) + { + var tokenQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)); + await DeleteDirectAsync(x => x.CreationDate < date && + x.Status != OpenIddictConstants.Statuses.Valid || + (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && + !tokenQueryable.Any(t => t.AuthorizationId == x.Id)), + GetCancellationToken(cancellationToken)); } } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs index 18d43a155e..26454e9204 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs @@ -100,20 +100,35 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default) + public virtual async Task> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default) { - var authorizationIds = await (await GetMongoQueryableAsync(cancellationToken)) - .Where(x => x.Status != OpenIddictConstants.Statuses.Valid) - .Select(x => x.Id) - .ToListAsync(GetCancellationToken(cancellationToken)); + return await (from token in await GetMongoQueryableAsync(cancellationToken) + join authorization in await GetMongoQueryableAsync(cancellationToken) + on token.AuthorizationId equals authorization.Id into ta + from a in ta + where token.CreationDate < date + where (token.Status != OpenIddictConstants.Statuses.Inactive && + token.Status != OpenIddictConstants.Statuses.Valid) || + (a != null && a.Status != OpenIddictConstants.Statuses.Valid) || + token.ExpirationDate < DateTime.UtcNow + orderby token.Id + select token).Take(count).ToListAsync(GetCancellationToken(cancellationToken)); + } - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) - .Where(x => x.CreationDate < date) - .Where(x => (x.Status != OpenIddictConstants.Statuses.Inactive && - x.Status != OpenIddictConstants.Statuses.Valid) || - authorizationIds.Contains(x.Id) || - x.ExpirationDate < DateTime.UtcNow) - .OrderBy(x => x.Id) - .Take(count).ToListAsync(GetCancellationToken(cancellationToken)); + public virtual async Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) + { + var tokens = await (from token in await GetMongoQueryableAsync(cancellationToken) + join authorization in await GetMongoQueryableAsync(cancellationToken) + on token.AuthorizationId equals authorization.Id into ta + from a in ta + where token.CreationDate < date + where (token.Status != OpenIddictConstants.Statuses.Inactive && + token.Status != OpenIddictConstants.Statuses.Valid) || + (a != null && a.Status != OpenIddictConstants.Statuses.Valid) || + token.ExpirationDate < DateTime.UtcNow + orderby token.Id + select token).ToListAsync(cancellationToken: cancellationToken); + + await DeleteManyAsync(tokens, cancellationToken: cancellationToken); } } From cca57c698941b8babced4603c6a73eff85e940b3 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 1 Dec 2022 17:30:24 +0800 Subject: [PATCH 2/3] Update TokenCleanupOptions.cs --- .../Volo/Abp/IdentityServer/Tokens/TokenCleanupOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupOptions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupOptions.cs index f432e827c6..715bd1cdd7 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupOptions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupOptions.cs @@ -24,7 +24,7 @@ public class TokenCleanupOptions /// /// Default value: 10. /// - /// [Obsolete("This option will be removed in future versions.")] + [Obsolete("This option will be removed in future versions.")] public int CleanupLoopCount { get; set; } = 10; /// From 219befc5dc539f15abec1fa0a7f7caa173bdefe1 Mon Sep 17 00:00:00 2001 From: maliming Date: Sun, 4 Dec 2022 09:21:06 +0800 Subject: [PATCH 3/3] Fix unit tests. --- .../IOpenIddictAuthorizationRepository.cs | 2 - .../Tokens/IOpenIddictTokenRepository.cs | 2 - ...EfCoreOpenIddictAuthorizationRepository.cs | 28 +++++-------- .../Tokens/EfCoreOpenIddictTokenRepository.cs | 28 +++---------- .../MongoOpenIddictAuthorizationRepository.cs | 26 ++++--------- .../Tokens/MongoOpenIddictTokenRepository.cs | 39 +++++++------------ .../AbpOpenIddictAuthorizationStore_Tests.cs | 4 +- ...OpenIddictAuthorizationRepository_Tests.cs | 17 ++++---- .../OpenIddictDataSeedContributor.cs | 30 +++++++------- .../OpenIddictTokenRepository_Tests.cs | 21 +++++----- 10 files changed, 73 insertions(+), 124 deletions(-) diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/IOpenIddictAuthorizationRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/IOpenIddictAuthorizationRepository.cs index c41df91386..0cca87ebb9 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/IOpenIddictAuthorizationRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/IOpenIddictAuthorizationRepository.cs @@ -22,7 +22,5 @@ public interface IOpenIddictAuthorizationRepository : IBasicRepository> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default); - Task> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default); - Task PruneAsync(DateTime date, CancellationToken cancellationToken = default); } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/IOpenIddictTokenRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/IOpenIddictTokenRepository.cs index 97e63ffb61..4ae9c41e27 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/IOpenIddictTokenRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/IOpenIddictTokenRepository.cs @@ -30,7 +30,5 @@ public interface IOpenIddictTokenRepository : IBasicRepository> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default); - Task> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default); - Task PruneAsync(DateTime date, CancellationToken cancellationToken = default); } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs index 54bc1a642b..ae5e4e18bd 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs +++ b/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; @@ -79,26 +80,15 @@ public class EfCoreOpenIddictAuthorizationRepository : EfCoreRepository> 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)); - } - public virtual async Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) { - var tokenQueryable = (await GetDbContextAsync()).Tokens.AsQueryable(); - await DeleteDirectAsync(x => x.CreationDate < date && - x.Status != OpenIddictConstants.Statuses.Valid || - (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && - !tokenQueryable.Any(t => t.AuthorizationId == x.Id)), - cancellationToken: cancellationToken); + await (from authorization in (await GetQueryableAsync()) + join token in (await GetDbContextAsync()).Set() + 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).ExecuteDeleteAsync(cancellationToken); } } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs index ffdea1518a..87af3706b1 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs @@ -87,34 +87,16 @@ public class EfCoreOpenIddictTokenRepository : EfCoreRepository> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default) - { - return await (from token in await GetQueryableAsync() - join authorization in (await GetDbContextAsync()).Set().AsQueryable() - on token.AuthorizationId equals authorization.Id into ta - from a in ta - where token.CreationDate < date - where (token.Status != OpenIddictConstants.Statuses.Inactive && - token.Status != OpenIddictConstants.Statuses.Valid) || - (a != null && a.Status != OpenIddictConstants.Statuses.Valid) || - token.ExpirationDate < DateTime.UtcNow - orderby token.Id - select token).Take(count) - .ToListAsync(GetCancellationToken(cancellationToken)); - } - public virtual async Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) { await (from token in await GetQueryableAsync() - join authorization in (await GetDbContextAsync()).Set().AsQueryable() - on token.AuthorizationId equals authorization.Id into ta - from a in ta + join authorization in (await GetDbContextAsync()).Set() + on token.AuthorizationId equals authorization.Id into tokenAuthorizations + from tokenAuthorization in tokenAuthorizations.DefaultIfEmpty() where token.CreationDate < date - where (token.Status != OpenIddictConstants.Statuses.Inactive && - token.Status != OpenIddictConstants.Statuses.Valid) || - (a != null && a.Status != OpenIddictConstants.Statuses.Valid) || + where (token.Status != OpenIddictConstants.Statuses.Inactive && token.Status != OpenIddictConstants.Statuses.Valid) || + (tokenAuthorization != null && tokenAuthorization.Status != OpenIddictConstants.Statuses.Valid) || token.ExpirationDate < DateTime.UtcNow - orderby token.Id select token) .ExecuteDeleteAsync(GetCancellationToken(cancellationToken)); } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs index a9de4e7949..0994501cd6 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs @@ -65,26 +65,16 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository>().ToListAsync(GetCancellationToken(cancellationToken)); } - public virtual async Task> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default) + public virtual async Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) { - var tokenQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)); - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) - .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) + var tokens = await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.AuthorizationId != null) + .Select(x => x.AuthorizationId.Value) .ToListAsync(GetCancellationToken(cancellationToken)); - } - public virtual async Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) - { - var tokenQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)); - await DeleteDirectAsync(x => x.CreationDate < date && - x.Status != OpenIddictConstants.Statuses.Valid || - (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && - !tokenQueryable.Any(t => t.AuthorizationId == x.Id)), - GetCancellationToken(cancellationToken)); + await DeleteManyAsync(await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.CreationDate < date) + .Where(x => x.Status == OpenIddictConstants.Statuses.Valid || (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && !tokens.Contains(x.Id))) + .ToListAsync(cancellationToken: cancellationToken), cancellationToken: cancellationToken); } } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs index 26454e9204..d10787a9f9 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs @@ -100,34 +100,21 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default) - { - return await (from token in await GetMongoQueryableAsync(cancellationToken) - join authorization in await GetMongoQueryableAsync(cancellationToken) - on token.AuthorizationId equals authorization.Id into ta - from a in ta - where token.CreationDate < date - where (token.Status != OpenIddictConstants.Statuses.Inactive && - token.Status != OpenIddictConstants.Statuses.Valid) || - (a != null && a.Status != OpenIddictConstants.Statuses.Valid) || - token.ExpirationDate < DateTime.UtcNow - orderby token.Id - select token).Take(count).ToListAsync(GetCancellationToken(cancellationToken)); - } - public virtual async Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) { - var tokens = await (from token in await GetMongoQueryableAsync(cancellationToken) - join authorization in await GetMongoQueryableAsync(cancellationToken) - on token.AuthorizationId equals authorization.Id into ta - from a in ta - where token.CreationDate < date - where (token.Status != OpenIddictConstants.Statuses.Inactive && - token.Status != OpenIddictConstants.Statuses.Valid) || - (a != null && a.Status != OpenIddictConstants.Statuses.Valid) || - token.ExpirationDate < DateTime.UtcNow - orderby token.Id - select token).ToListAsync(cancellationToken: cancellationToken); + var authorizationIds = await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.Status != OpenIddictConstants.Statuses.Valid) + .Select(x => x.Id) + .ToListAsync(GetCancellationToken(cancellationToken)); + + var tokens = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + .Where(x => x.CreationDate < date) + .Where(x => (x.Status != OpenIddictConstants.Statuses.Inactive && + x.Status != OpenIddictConstants.Statuses.Valid) || + authorizationIds.Contains(x.Id) || + x.ExpirationDate < DateTime.UtcNow) + .OrderBy(x => x.Id) + .ToListAsync(GetCancellationToken(cancellationToken)); await DeleteManyAsync(tokens, cancellationToken: cancellationToken); } diff --git a/modules/openiddict/test/Volo.Abp.OpenIddict.Domain.Tests/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore_Tests.cs b/modules/openiddict/test/Volo.Abp.OpenIddict.Domain.Tests/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore_Tests.cs index a392d1f89c..2fbd875713 100644 --- a/modules/openiddict/test/Volo.Abp.OpenIddict.Domain.Tests/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore_Tests.cs +++ b/modules/openiddict/test/Volo.Abp.OpenIddict.Domain.Tests/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore_Tests.cs @@ -69,7 +69,7 @@ public class AbpOpenIddictAuthorizationStore_Tests : OpenIddictDomainTestBase { var authorization = await _authorizationStore.FindByIdAsync(_testData.Authorization1Id.ToString(), CancellationToken.None); authorization.ShouldNotBeNull(); - authorization.Status.ShouldBe("TestStatus1"); + authorization.Status.ShouldBe(OpenIddictConstants.Statuses.Valid); authorization.Subject.ShouldBe("TestSubject1"); authorization.Type.ShouldBe(OpenIddictConstants.AuthorizationTypes.Permanent); } @@ -125,4 +125,4 @@ public class AbpOpenIddictAuthorizationStore_Tests : OpenIddictDomainTestBase authorization.Type.ShouldBe(OpenIddictConstants.AuthorizationTypes.AdHoc); authorization.ApplicationId.ShouldBe(_testData.App2Id); } -} \ No newline at end of file +} diff --git a/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictAuthorizationRepository_Tests.cs b/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictAuthorizationRepository_Tests.cs index 72e82d6ebe..529849ed66 100644 --- a/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictAuthorizationRepository_Tests.cs +++ b/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictAuthorizationRepository_Tests.cs @@ -20,16 +20,16 @@ public abstract class OpenIddictAuthorizationRepository_Tests : _authorizationRepository = GetRequiredService(); _testData = GetRequiredService(); } - + [Fact] public async Task FindAsync() { (await _authorizationRepository.FindAsync(subject:"TestSubject1", client: new Guid())).Count.ShouldBe(0); (await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id)).Count.ShouldBe(1); (await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: "NonExistsStatus")).Count.ShouldBe(0); - (await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: "TestStatus1")).Count.ShouldBe(1); - (await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: "TestStatus1" ,type: "NonExistsType")).Count.ShouldBe(0); - (await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: "TestStatus1" ,type: OpenIddictConstants.AuthorizationTypes.Permanent)).Count.ShouldBe(1); + (await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: OpenIddictConstants.Statuses.Valid)).Count.ShouldBe(1); + (await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: OpenIddictConstants.Statuses.Valid ,type: "NonExistsType")).Count.ShouldBe(0); + (await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: OpenIddictConstants.Statuses.Valid ,type: OpenIddictConstants.AuthorizationTypes.Permanent)).Count.ShouldBe(1); } [Fact] @@ -64,9 +64,10 @@ public abstract class OpenIddictAuthorizationRepository_Tests : } [Fact] - public async Task GetPruneListAsync() + public async Task PruneAsync() { - var threshold = DateTime.UtcNow - TimeSpan.FromDays(14); - (await _authorizationRepository.GetPruneListAsync(threshold, int.MaxValue)).Count.ShouldBe(1); + (await _authorizationRepository.ListAsync(int.MaxValue, 0)).Count.ShouldBe(2); + await _authorizationRepository.PruneAsync(DateTime.UtcNow - TimeSpan.FromDays(14)); + (await _authorizationRepository.ListAsync(int.MaxValue, 0)).Count.ShouldBe(1); } -} \ No newline at end of file +} diff --git a/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictDataSeedContributor.cs b/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictDataSeedContributor.cs index 1b9dbed4ca..eccdf828c6 100644 --- a/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictDataSeedContributor.cs +++ b/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictDataSeedContributor.cs @@ -25,9 +25,9 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep private readonly IClock _clock; public OpenIddictDataSeedContributor( - IOpenIddictApplicationManager applicationManager, + IOpenIddictApplicationManager applicationManager, IOpenIddictScopeManager scopeManager, - IOpenIddictTokenManager tokenManager, + IOpenIddictTokenManager tokenManager, IOpenIddictAuthorizationManager authorizationManager, IClock clock, AbpOpenIddictTestData testData) @@ -65,7 +65,7 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep "TestScope1Resource" } })); - + await _scopeManager.CreateAsync(await GetOpenIddictScopeModelAsync(_testData.Scope2Id, new OpenIddictScopeDescriptor() { Name = _testData.Scope2Name, @@ -89,7 +89,7 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep await _scopeManager.PopulateAsync(scope, scopeDescriptor); return scope; } - + private async Task CreateApplicationsAsync() { await _applicationManager.CreateAsync(await GetOpenIddictApplicationModelAsync(_testData.App1Id, new OpenIddictApplicationDescriptor @@ -138,8 +138,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep OpenIddictConstants.Permissions.Prefixes.Scope + _testData.Scope1Name } - })); - + })); + await _applicationManager.CreateAsync(await GetOpenIddictApplicationModelAsync(_testData.App2Id, new OpenIddictApplicationDescriptor { ClientId = _testData.App2ClientId, @@ -211,11 +211,11 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep ExpirationDate = _clock.Now.AddDays(-30), CreationDate = _clock.Now.AddDays(-30) })); - + await _tokenManager.CreateAsync(await GetOpenIddictTokenModelAsync(_testData.Token2Id, new OpenIddictTokenDescriptor { ApplicationId = _testData.App2Id.ToString(), - AuthorizationId = _testData.Authorization2Id.ToString(), + AuthorizationId = _testData.Authorization1Id.ToString(), Subject = "TestSubject2", Type = "TestType2", Status = OpenIddictConstants.Statuses.Valid, @@ -236,23 +236,23 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep await _authorizationManager.CreateAsync(await GetOpenIddictAuthorizationModelAsync(_testData.Authorization1Id, new OpenIddictAuthorizationDescriptor { ApplicationId = _testData.App1Id.ToString(), - Status = "TestStatus1", + Status = OpenIddictConstants.Statuses.Valid, Subject = "TestSubject1", Type = OpenIddictConstants.AuthorizationTypes.Permanent, - CreationDate = _clock.Now.AddDays(-30) - + CreationDate = _clock.Now + })); - + await _authorizationManager.CreateAsync(await GetOpenIddictAuthorizationModelAsync(_testData.Authorization2Id, new OpenIddictAuthorizationDescriptor { ApplicationId = _testData.App2Id.ToString(), - Status = "TestStatus2", + Status = OpenIddictConstants.Statuses.Inactive, Subject = "TestSubject2", Type = OpenIddictConstants.AuthorizationTypes.AdHoc, - CreationDate = _clock.Now + CreationDate = _clock.Now.AddDays(-30) })); } - + private async Task GetOpenIddictAuthorizationModelAsync(Guid id, OpenIddictAuthorizationDescriptor authorizationDescriptor) { var authorization = new OpenIddictAuthorizationModel{Id = id}; diff --git a/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictTokenRepository_Tests.cs b/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictTokenRepository_Tests.cs index 4ed651eee6..1a6c68eb2b 100644 --- a/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictTokenRepository_Tests.cs +++ b/modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictTokenRepository_Tests.cs @@ -25,7 +25,7 @@ public abstract class OpenIddictTokenRepository_Tests : OpenIddi { await _tokenRepository.DeleteManyByApplicationIdAsync(new Guid()); (await _tokenRepository.GetCountAsync()).ShouldBe(2); - + await _tokenRepository.DeleteManyByApplicationIdAsync(_testData.App1Id); (await _tokenRepository.GetCountAsync()).ShouldBe(1); } @@ -35,9 +35,9 @@ public abstract class OpenIddictTokenRepository_Tests : OpenIddi { await _tokenRepository.DeleteManyByAuthorizationIdAsync(new Guid()); (await _tokenRepository.GetCountAsync()).ShouldBe(2); - + await _tokenRepository.DeleteManyByAuthorizationIdAsync(_testData.Authorization1Id); - (await _tokenRepository.GetCountAsync()).ShouldBe(1); + (await _tokenRepository.GetCountAsync()).ShouldBe(0); } [Fact] @@ -60,7 +60,7 @@ public abstract class OpenIddictTokenRepository_Tests : OpenIddi [Fact] public async Task FindByAuthorizationIdAsync() { - (await _tokenRepository.FindByAuthorizationIdAsync(_testData.Authorization1Id)).Count.ShouldBe(1); + (await _tokenRepository.FindByAuthorizationIdAsync(_testData.Authorization1Id)).Count.ShouldBe(2); } [Fact] @@ -87,7 +87,7 @@ public abstract class OpenIddictTokenRepository_Tests : OpenIddi { (await _tokenRepository.FindBySubjectAsync("TestSubject1")).Count.ShouldBe(1); } - + [Fact] public async Task ListAsync() { @@ -96,9 +96,12 @@ public abstract class OpenIddictTokenRepository_Tests : OpenIddi } [Fact] - public async Task GetPruneListAsync() + public async Task PruneAsync() { - var threshold = DateTime.UtcNow - TimeSpan.FromDays(14); - (await _tokenRepository.GetPruneListAsync(threshold, int.MaxValue)).Count.ShouldBe(1); + (await _tokenRepository.ListAsync(int.MaxValue, 0)).Count.ShouldBe(2); + + await _tokenRepository.PruneAsync(DateTime.UtcNow - TimeSpan.FromDays(14)); + + (await _tokenRepository.ListAsync(int.MaxValue, 0)).Count.ShouldBe(1); } -} \ No newline at end of file +}