From b44d49a6abc7e36665f7bf7f42b2f24c004b22d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sun, 26 Jul 2026 16:20:11 +0200 Subject: [PATCH] Remove the Enumerable.Contains() workaround from the MongoDB stores --- .../Stores/OpenIddictMongoDbAuthorizationStore.cs | 4 +--- .../Stores/OpenIddictMongoDbResourceStore.cs | 4 +--- src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs | 4 +--- src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs index fa02cb24..d361008c 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs @@ -382,9 +382,7 @@ public class OpenIddictMongoDbAuthorizationStore< // maximum number of elements that can be removed by a single call to PruneAsync() is deliberately limited. foreach (var chunk in identifiers.Take(1_000_000).Chunk(1_000)) { - // Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure the - // span-based MemoryExtensions.Contains() API (which is not supported by MongoDB) is not used instead. - result += (await collection.DeleteManyAsync(authorization => Enumerable.Contains(chunk, authorization.Id), cancellationToken)).DeletedCount; + result += (await collection.DeleteManyAsync(authorization => chunk.Contains(authorization.Id), cancellationToken)).DeletedCount; } return result; diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs index 2f985ac5..be31f8a2 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs @@ -142,9 +142,7 @@ public class OpenIddictMongoDbResourceStore< var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ResourcesCollectionName); - // Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure - // ImmutableArray.Contains() (which is not fully supported by MongoDB) is not used instead. - await foreach (var resource in collection.Find(resource => Enumerable.Contains(names, resource.Name)).ToAsyncEnumerable(cancellationToken)) + await foreach (var resource in collection.Find(resource => names.Contains(resource.Name!)).ToAsyncEnumerable(cancellationToken)) { yield return resource; } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs index 60f34c03..5f6ea031 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs @@ -142,9 +142,7 @@ public class OpenIddictMongoDbScopeStore< var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); - // Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure - // ImmutableArray.Contains() (which is not fully supported by MongoDB) is not used instead. - await foreach (var scope in collection.Find(scope => Enumerable.Contains(names, scope.Name)).ToAsyncEnumerable(cancellationToken)) + await foreach (var scope in collection.Find(scope => names.Contains(scope.Name!)).ToAsyncEnumerable(cancellationToken)) { yield return scope; } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs index 6d719c7e..07bffcd4 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs @@ -430,9 +430,7 @@ public class OpenIddictMongoDbTokenStore< // maximum number of elements that can be removed by a single call to PruneAsync() is deliberately limited. foreach (var chunk in identifiers.Take(1_000_000).Chunk(1_000)) { - // Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure the - // span-based MemoryExtensions.Contains() API (which is not supported by MongoDB) is not used instead. - result += (await collection.DeleteManyAsync(token => Enumerable.Contains(chunk, token.Id), cancellationToken)).DeletedCount; + result += (await collection.DeleteManyAsync(token => chunk.Contains(token.Id), cancellationToken)).DeletedCount; } return result;