From 8fdabc71a159a569575726f4da73a0ba27653d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sun, 6 Oct 2019 17:47:25 +0200 Subject: [PATCH] Use Enumerable.Contains() instead of ImmutableArray.Contains() and add missing cancellation tokens --- .../Stores/OpenIddictApplicationStore.cs | 14 +++++++------- .../Stores/OpenIddictAuthorizationStore.cs | 6 +++--- .../Stores/OpenIddictScopeStore.cs | 10 ++++++---- .../Stores/OpenIddictTokenStore.cs | 4 ++-- .../Stores/OpenIddictApplicationStore.cs | 10 +++++----- .../Stores/OpenIddictAuthorizationStore.cs | 6 +++--- .../Stores/OpenIddictScopeStore.cs | 9 ++++++--- .../Stores/OpenIddictTokenStore.cs | 4 ++-- .../Stores/OpenIddictApplicationStore.cs | 4 ++-- .../Stores/OpenIddictAuthorizationStore.cs | 4 ++-- .../Stores/OpenIddictScopeStore.cs | 8 +++++--- .../Stores/OpenIddictTokenStore.cs | 4 ++-- 12 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs index 3a1de64d..4f7f561e 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs @@ -107,7 +107,7 @@ namespace OpenIddict.EntityFramework /// whose result returns the number of applications in the database. /// public virtual Task CountAsync(CancellationToken cancellationToken) - => Applications.LongCountAsync(); + => Applications.LongCountAsync(cancellationToken); /// /// Determines the number of applications that match the specified query. @@ -126,7 +126,7 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(query)); } - return query(Applications).LongCountAsync(); + return query(Applications).LongCountAsync(cancellationToken); } /// @@ -249,7 +249,7 @@ namespace OpenIddict.EntityFramework return (from application in Applications where application.Id.Equals(key) - select application).FirstOrDefaultAsync(); + select application).FirstOrDefaultAsync(cancellationToken); } /// @@ -270,7 +270,7 @@ namespace OpenIddict.EntityFramework return (from application in Applications where application.ClientId == identifier - select application).FirstOrDefaultAsync(); + select application).FirstOrDefaultAsync(cancellationToken); } /// @@ -539,7 +539,7 @@ namespace OpenIddict.EntityFramework .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.Permissions) - .Select(element => (string) element) + .Select(permission => (string) permission) .ToImmutableArray(); }); @@ -576,7 +576,7 @@ namespace OpenIddict.EntityFramework .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.PostLogoutRedirectUris) - .Select(element => (string) element) + .Select(address => (string) address) .ToImmutableArray(); }); @@ -648,7 +648,7 @@ namespace OpenIddict.EntityFramework .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.RedirectUris) - .Select(element => (string) element) + .Select(address => (string) address) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs index 15549405..2145d478 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs @@ -107,7 +107,7 @@ namespace OpenIddict.EntityFramework /// whose result returns the number of authorizations in the database. /// public virtual Task CountAsync(CancellationToken cancellationToken) - => Authorizations.LongCountAsync(); + => Authorizations.LongCountAsync(cancellationToken); /// /// Determines the number of authorizations that match the specified query. @@ -126,7 +126,7 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(query)); } - return query(Authorizations).LongCountAsync(); + return query(Authorizations).LongCountAsync(cancellationToken); } /// @@ -594,7 +594,7 @@ namespace OpenIddict.EntityFramework .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(authorization.Scopes) - .Select(element => (string) element) + .Select(scope => (string) scope) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs index 0f657bae..1c86d014 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs @@ -89,7 +89,7 @@ namespace OpenIddict.EntityFramework /// whose result returns the number of scopes in the database. /// public virtual Task CountAsync(CancellationToken cancellationToken) - => Scopes.LongCountAsync(); + => Scopes.LongCountAsync(cancellationToken); /// /// Determines the number of scopes that match the specified query. @@ -108,7 +108,7 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(query)); } - return query(Scopes).LongCountAsync(); + return query(Scopes).LongCountAsync(cancellationToken); } /// @@ -223,9 +223,11 @@ namespace OpenIddict.EntityFramework throw new ArgumentException("Scope names cannot be null or empty.", nameof(names)); } + // Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure + // ImmutableArray.Contains() (which is not fully supported by Entity Framework 6.x) is not used instead. return ImmutableArray.CreateRange( await (from scope in Scopes - where names.Contains(scope.Name) + where Enumerable.Contains(names, scope.Name) select scope).ToListAsync(cancellationToken)); } @@ -434,7 +436,7 @@ namespace OpenIddict.EntityFramework .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(scope.Resources) - .Select(element => (string) element) + .Select(resource => (string) resource) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs index ed6ef8e5..5392cf1e 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs @@ -107,7 +107,7 @@ namespace OpenIddict.EntityFramework /// whose result returns the number of applications in the database. /// public virtual Task CountAsync(CancellationToken cancellationToken) - => Tokens.LongCountAsync(); + => Tokens.LongCountAsync(cancellationToken); /// /// Determines the number of tokens that match the specified query. @@ -126,7 +126,7 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(query)); } - return query(Tokens).LongCountAsync(); + return query(Tokens).LongCountAsync(cancellationToken); } /// diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs index bddb7701..a1a362cc 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs @@ -128,7 +128,7 @@ namespace OpenIddict.EntityFrameworkCore /// whose result returns the number of applications in the database. /// public virtual Task CountAsync(CancellationToken cancellationToken) - => Applications.LongCountAsync(); + => Applications.LongCountAsync(cancellationToken); /// /// Determines the number of applications that match the specified query. @@ -147,7 +147,7 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(query)); } - return query(Applications).LongCountAsync(); + return query(Applications).LongCountAsync(cancellationToken); } /// @@ -582,7 +582,7 @@ namespace OpenIddict.EntityFrameworkCore .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.Permissions) - .Select(element => (string) element) + .Select(permission => (string) permission) .ToImmutableArray(); }); @@ -619,7 +619,7 @@ namespace OpenIddict.EntityFrameworkCore .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.PostLogoutRedirectUris) - .Select(element => (string) element) + .Select(address => (string) address) .ToImmutableArray(); }); @@ -691,7 +691,7 @@ namespace OpenIddict.EntityFrameworkCore .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.RedirectUris) - .Select(element => (string) element) + .Select(address => (string) address) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs index d056ecb2..f9aa7271 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs @@ -128,7 +128,7 @@ namespace OpenIddict.EntityFrameworkCore /// whose result returns the number of authorizations in the database. /// public virtual Task CountAsync(CancellationToken cancellationToken) - => Authorizations.LongCountAsync(); + => Authorizations.LongCountAsync(cancellationToken); /// /// Determines the number of authorizations that match the specified query. @@ -147,7 +147,7 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(query)); } - return query(Authorizations).LongCountAsync(); + return query(Authorizations).LongCountAsync(cancellationToken); } /// @@ -652,7 +652,7 @@ namespace OpenIddict.EntityFrameworkCore .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(authorization.Scopes) - .Select(element => (string) element) + .Select(scope => (string) scope) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs index 9f4aee41..d127182b 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs @@ -106,7 +106,7 @@ namespace OpenIddict.EntityFrameworkCore /// whose result returns the number of scopes in the database. /// public virtual Task CountAsync(CancellationToken cancellationToken) - => Scopes.LongCountAsync(); + => Scopes.LongCountAsync(cancellationToken); /// /// Determines the number of scopes that match the specified query. @@ -125,7 +125,7 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(query)); } - return query(Scopes).LongCountAsync(); + return query(Scopes).LongCountAsync(cancellationToken); } /// @@ -240,9 +240,12 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentException("Scope names cannot be null or empty.", nameof(names)); } + // Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure + // ImmutableArray.Contains() (which is not fully supported by Entity Framework Core) is not used instead. return ImmutableArray.CreateRange( await (from scope in Scopes.AsTracking() where names.Contains(scope.Name) + where Enumerable.Contains(names, scope.Name) select scope).ToListAsync(cancellationToken)); } @@ -451,7 +454,7 @@ namespace OpenIddict.EntityFrameworkCore .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(scope.Resources) - .Select(element => (string) element) + .Select(resource => (string) resource) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs index 7b95b288..d3de1216 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs @@ -128,7 +128,7 @@ namespace OpenIddict.EntityFrameworkCore /// whose result returns the number of applications in the database. /// public virtual Task CountAsync(CancellationToken cancellationToken) - => Tokens.LongCountAsync(); + => Tokens.LongCountAsync(cancellationToken); /// /// Determines the number of tokens that match the specified query. @@ -147,7 +147,7 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(query)); } - return query(Tokens).LongCountAsync(); + return query(Tokens).LongCountAsync(cancellationToken); } /// diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs index 4accb1fe..f2bdc763 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs @@ -61,7 +61,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName); - return await collection.CountDocumentsAsync(FilterDefinition.Empty); + return await collection.CountDocumentsAsync(FilterDefinition.Empty, null, cancellationToken); } /// @@ -85,7 +85,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName); - return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(); + return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(cancellationToken); } /// diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs index c76438d4..c32a9c83 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs @@ -61,7 +61,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName); - return await collection.CountDocumentsAsync(FilterDefinition.Empty); + return await collection.CountDocumentsAsync(FilterDefinition.Empty, null, cancellationToken); } /// @@ -85,7 +85,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName); - return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(); + return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(cancellationToken); } /// diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs index c5286161..7d8fc65c 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs @@ -61,7 +61,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); - return await collection.CountDocumentsAsync(FilterDefinition.Empty); + return await collection.CountDocumentsAsync(FilterDefinition.Empty, null, cancellationToken); } /// @@ -85,7 +85,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); - return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(); + return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(cancellationToken); } /// @@ -202,7 +202,9 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); - return ImmutableArray.CreateRange(await collection.Find(scope => names.Contains(scope.Name)).ToListAsync(cancellationToken)); + // 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. + return ImmutableArray.CreateRange(await collection.Find(scope => Enumerable.Contains(names, scope.Name)).ToListAsync(cancellationToken)); } /// diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs index cacd8d1b..9abfed98 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs @@ -61,7 +61,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName); - return await collection.CountDocumentsAsync(FilterDefinition.Empty); + return await collection.CountDocumentsAsync(FilterDefinition.Empty, null, cancellationToken); } /// @@ -85,7 +85,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName); - return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(); + return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(cancellationToken); } ///