Browse Source

Use Enumerable.Contains() instead of ImmutableArray.Contains() and add missing cancellation tokens

pull/2236/head
Kévin Chalet 7 years ago
parent
commit
8fdabc71a1
  1. 14
      src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs
  2. 6
      src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs
  3. 10
      src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs
  4. 4
      src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs
  5. 10
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
  6. 6
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
  7. 9
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs
  8. 4
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs
  9. 4
      src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs
  10. 4
      src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs
  11. 8
      src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs
  12. 4
      src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs

14
src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs

@ -107,7 +107,7 @@ namespace OpenIddict.EntityFramework
/// whose result returns the number of applications in the database.
/// </returns>
public virtual Task<long> CountAsync(CancellationToken cancellationToken)
=> Applications.LongCountAsync();
=> Applications.LongCountAsync(cancellationToken);
/// <summary>
/// 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);
}
/// <summary>
@ -249,7 +249,7 @@ namespace OpenIddict.EntityFramework
return (from application in Applications
where application.Id.Equals(key)
select application).FirstOrDefaultAsync();
select application).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -270,7 +270,7 @@ namespace OpenIddict.EntityFramework
return (from application in Applications
where application.ClientId == identifier
select application).FirstOrDefaultAsync();
select application).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -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();
});

6
src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs

@ -107,7 +107,7 @@ namespace OpenIddict.EntityFramework
/// whose result returns the number of authorizations in the database.
/// </returns>
public virtual Task<long> CountAsync(CancellationToken cancellationToken)
=> Authorizations.LongCountAsync();
=> Authorizations.LongCountAsync(cancellationToken);
/// <summary>
/// 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);
}
/// <summary>
@ -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();
});

10
src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs

@ -89,7 +89,7 @@ namespace OpenIddict.EntityFramework
/// whose result returns the number of scopes in the database.
/// </returns>
public virtual Task<long> CountAsync(CancellationToken cancellationToken)
=> Scopes.LongCountAsync();
=> Scopes.LongCountAsync(cancellationToken);
/// <summary>
/// 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);
}
/// <summary>
@ -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();
});

4
src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs

@ -107,7 +107,7 @@ namespace OpenIddict.EntityFramework
/// whose result returns the number of applications in the database.
/// </returns>
public virtual Task<long> CountAsync(CancellationToken cancellationToken)
=> Tokens.LongCountAsync();
=> Tokens.LongCountAsync(cancellationToken);
/// <summary>
/// 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);
}
/// <summary>

10
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs

@ -128,7 +128,7 @@ namespace OpenIddict.EntityFrameworkCore
/// whose result returns the number of applications in the database.
/// </returns>
public virtual Task<long> CountAsync(CancellationToken cancellationToken)
=> Applications.LongCountAsync();
=> Applications.LongCountAsync(cancellationToken);
/// <summary>
/// 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);
}
/// <summary>
@ -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();
});

6
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs

@ -128,7 +128,7 @@ namespace OpenIddict.EntityFrameworkCore
/// whose result returns the number of authorizations in the database.
/// </returns>
public virtual Task<long> CountAsync(CancellationToken cancellationToken)
=> Authorizations.LongCountAsync();
=> Authorizations.LongCountAsync(cancellationToken);
/// <summary>
/// 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);
}
/// <summary>
@ -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();
});

9
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs

@ -106,7 +106,7 @@ namespace OpenIddict.EntityFrameworkCore
/// whose result returns the number of scopes in the database.
/// </returns>
public virtual Task<long> CountAsync(CancellationToken cancellationToken)
=> Scopes.LongCountAsync();
=> Scopes.LongCountAsync(cancellationToken);
/// <summary>
/// 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);
}
/// <summary>
@ -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();
});

4
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs

@ -128,7 +128,7 @@ namespace OpenIddict.EntityFrameworkCore
/// whose result returns the number of applications in the database.
/// </returns>
public virtual Task<long> CountAsync(CancellationToken cancellationToken)
=> Tokens.LongCountAsync();
=> Tokens.LongCountAsync(cancellationToken);
/// <summary>
/// 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);
}
/// <summary>

4
src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs

@ -61,7 +61,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TApplication>(Options.CurrentValue.ApplicationsCollectionName);
return await collection.CountDocumentsAsync(FilterDefinition<TApplication>.Empty);
return await collection.CountDocumentsAsync(FilterDefinition<TApplication>.Empty, null, cancellationToken);
}
/// <summary>
@ -85,7 +85,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TApplication>(Options.CurrentValue.ApplicationsCollectionName);
return await ((IMongoQueryable<TApplication>) query(collection.AsQueryable())).LongCountAsync();
return await ((IMongoQueryable<TApplication>) query(collection.AsQueryable())).LongCountAsync(cancellationToken);
}
/// <summary>

4
src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs

@ -61,7 +61,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TAuthorization>(Options.CurrentValue.AuthorizationsCollectionName);
return await collection.CountDocumentsAsync(FilterDefinition<TAuthorization>.Empty);
return await collection.CountDocumentsAsync(FilterDefinition<TAuthorization>.Empty, null, cancellationToken);
}
/// <summary>
@ -85,7 +85,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TAuthorization>(Options.CurrentValue.AuthorizationsCollectionName);
return await ((IMongoQueryable<TAuthorization>) query(collection.AsQueryable())).LongCountAsync();
return await ((IMongoQueryable<TAuthorization>) query(collection.AsQueryable())).LongCountAsync(cancellationToken);
}
/// <summary>

8
src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs

@ -61,7 +61,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TScope>(Options.CurrentValue.ScopesCollectionName);
return await collection.CountDocumentsAsync(FilterDefinition<TScope>.Empty);
return await collection.CountDocumentsAsync(FilterDefinition<TScope>.Empty, null, cancellationToken);
}
/// <summary>
@ -85,7 +85,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TScope>(Options.CurrentValue.ScopesCollectionName);
return await ((IMongoQueryable<TScope>) query(collection.AsQueryable())).LongCountAsync();
return await ((IMongoQueryable<TScope>) query(collection.AsQueryable())).LongCountAsync(cancellationToken);
}
/// <summary>
@ -202,7 +202,9 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TScope>(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));
}
/// <summary>

4
src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs

@ -61,7 +61,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TToken>(Options.CurrentValue.TokensCollectionName);
return await collection.CountDocumentsAsync(FilterDefinition<TToken>.Empty);
return await collection.CountDocumentsAsync(FilterDefinition<TToken>.Empty, null, cancellationToken);
}
/// <summary>
@ -85,7 +85,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TToken>(Options.CurrentValue.TokensCollectionName);
return await ((IMongoQueryable<TToken>) query(collection.AsQueryable())).LongCountAsync();
return await ((IMongoQueryable<TToken>) query(collection.AsQueryable())).LongCountAsync(cancellationToken);
}
/// <summary>

Loading…
Cancel
Save