Browse Source

Use ToListAsync() instead of ToArrayAsync() to save an intermediate allocation

pull/516/head
Kévin Chalet 9 years ago
parent
commit
83eddce4f4
  1. 15
      src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs
  2. 11
      src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs
  3. 6
      src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs
  4. 6
      src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs
  5. 15
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
  6. 13
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
  7. 6
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs
  8. 10
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs

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

@ -5,6 +5,7 @@
*/ */
using System; using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Data.Entity; using System.Data.Entity;
using System.Linq; using System.Linq;
@ -108,7 +109,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Applications).LongCountAsync(); return query(Applications).LongCountAsync();
} }
/// <summary> /// <summary>
@ -169,18 +170,18 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(application)); throw new ArgumentNullException(nameof(application));
} }
Task<TAuthorization[]> ListAuthorizationsAsync() Task<List<TAuthorization>> ListAuthorizationsAsync()
{ {
return (from authorization in Authorizations.Include(authorization => authorization.Tokens) return (from authorization in Authorizations.Include(authorization => authorization.Tokens)
where authorization.Application.Id.Equals(application.Id) where authorization.Application.Id.Equals(application.Id)
select authorization).ToArrayAsync(cancellationToken); select authorization).ToListAsync(cancellationToken);
} }
Task<TToken[]> ListTokensAsync() Task<List<TToken>> ListTokensAsync()
{ {
return (from token in Tokens return (from token in Tokens
where token.Application.Id.Equals(application.Id) where token.Application.Id.Equals(application.Id)
select token).ToArrayAsync(cancellationToken); select token).ToListAsync(cancellationToken);
} }
// Remove all the authorizations associated with the application and // Remove all the authorizations associated with the application and
@ -242,7 +243,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Applications).SingleOrDefaultAsync(cancellationToken); return query(Applications).SingleOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@ -262,7 +263,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return ImmutableArray.Create(await query.Invoke(Applications).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await query(Applications).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>

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

@ -5,6 +5,7 @@
*/ */
using System; using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Data.Entity; using System.Data.Entity;
using System.Linq; using System.Linq;
@ -108,7 +109,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Authorizations).LongCountAsync(); return query(Authorizations).LongCountAsync();
} }
/// <summary> /// <summary>
@ -169,11 +170,11 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(authorization)); throw new ArgumentNullException(nameof(authorization));
} }
Task<TToken[]> ListTokensAsync() Task<List<TToken>> ListTokensAsync()
{ {
return (from token in Tokens return (from token in Tokens
where token.Application.Id.Equals(authorization.Id) where token.Application.Id.Equals(authorization.Id)
select token).ToArrayAsync(cancellationToken); select token).ToListAsync(cancellationToken);
} }
// Remove all the tokens associated with the application. // Remove all the tokens associated with the application.
@ -255,7 +256,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Authorizations).SingleOrDefaultAsync(cancellationToken); return query(Authorizations).SingleOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@ -275,7 +276,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return ImmutableArray.Create(await query.Invoke(Authorizations).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await query(Authorizations).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>

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

@ -89,7 +89,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Scopes).LongCountAsync(); return query(Scopes).LongCountAsync();
} }
/// <summary> /// <summary>
@ -167,7 +167,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Scopes).SingleOrDefaultAsync(cancellationToken); return query(Scopes).SingleOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@ -187,7 +187,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return ImmutableArray.Create(await query.Invoke(Scopes).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await query(Scopes).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>

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

@ -108,7 +108,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Tokens).LongCountAsync(); return query(Tokens).LongCountAsync();
} }
/// <summary> /// <summary>
@ -240,7 +240,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Tokens).SingleOrDefaultAsync(cancellationToken); return query(Tokens).SingleOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@ -292,7 +292,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return ImmutableArray.Create(await query.Invoke(Tokens).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await query(Tokens).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>

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

@ -5,6 +5,7 @@
*/ */
using System; using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@ -108,7 +109,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Applications).LongCountAsync(); return query(Applications).LongCountAsync();
} }
/// <summary> /// <summary>
@ -169,18 +170,18 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(application)); throw new ArgumentNullException(nameof(application));
} }
Task<TAuthorization[]> ListAuthorizationsAsync() Task<List<TAuthorization>> ListAuthorizationsAsync()
{ {
return (from authorization in Authorizations.Include(authorization => authorization.Tokens) return (from authorization in Authorizations.Include(authorization => authorization.Tokens)
where authorization.Application.Id.Equals(application.Id) where authorization.Application.Id.Equals(application.Id)
select authorization).ToArrayAsync(cancellationToken); select authorization).ToListAsync(cancellationToken);
} }
Task<TToken[]> ListTokensAsync() Task<List<TToken>> ListTokensAsync()
{ {
return (from token in Tokens return (from token in Tokens
where token.Application.Id.Equals(application.Id) where token.Application.Id.Equals(application.Id)
select token).ToArrayAsync(cancellationToken); select token).ToListAsync(cancellationToken);
} }
// Remove all the authorizations associated with the application and // Remove all the authorizations associated with the application and
@ -242,7 +243,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Applications).SingleOrDefaultAsync(cancellationToken); return query(Applications).SingleOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@ -262,7 +263,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return ImmutableArray.Create(await query.Invoke(Applications).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await query(Applications).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>

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

@ -5,6 +5,7 @@
*/ */
using System; using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@ -108,7 +109,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Authorizations).LongCountAsync(); return query(Authorizations).LongCountAsync();
} }
/// <summary> /// <summary>
@ -169,11 +170,11 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(authorization)); throw new ArgumentNullException(nameof(authorization));
} }
Task<TToken[]> ListTokensAsync() Task<List<TToken>> ListTokensAsync()
{ {
return (from token in Tokens return (from token in Tokens
where token.Application.Id.Equals(authorization.Id) where token.Application.Id.Equals(authorization.Id)
select token).ToArrayAsync(cancellationToken); select token).ToListAsync(cancellationToken);
} }
// Remove all the tokens associated with the application. // Remove all the tokens associated with the application.
@ -226,7 +227,7 @@ namespace OpenIddict.EntityFrameworkCore
select authorization; select authorization;
} }
return ImmutableArray.Create(await Query(Authorizations, Applications).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await Query(Authorizations, Applications).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>
@ -297,7 +298,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Authorizations).SingleOrDefaultAsync(cancellationToken); return query(Authorizations).SingleOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@ -317,7 +318,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return ImmutableArray.Create(await query.Invoke(Authorizations).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await query(Authorizations).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>

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

@ -89,7 +89,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Scopes).LongCountAsync(); return query(Scopes).LongCountAsync();
} }
/// <summary> /// <summary>
@ -167,7 +167,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Scopes).SingleOrDefaultAsync(cancellationToken); return query(Scopes).SingleOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@ -187,7 +187,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return ImmutableArray.Create(await query.Invoke(Scopes).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await query(Scopes).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>

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

@ -108,7 +108,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Tokens).LongCountAsync(); return query(Tokens).LongCountAsync();
} }
/// <summary> /// <summary>
@ -203,7 +203,7 @@ namespace OpenIddict.EntityFrameworkCore
select token; select token;
} }
return ImmutableArray.Create(await Query(Applications, Tokens).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await Query(Applications, Tokens).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>
@ -237,7 +237,7 @@ namespace OpenIddict.EntityFrameworkCore
select token; select token;
} }
return ImmutableArray.Create(await Query(Authorizations, Tokens).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await Query(Authorizations, Tokens).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>
@ -308,7 +308,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return query.Invoke(Tokens).SingleOrDefaultAsync(cancellationToken); return query(Tokens).SingleOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@ -360,7 +360,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
} }
return ImmutableArray.Create(await query.Invoke(Tokens).ToArrayAsync(cancellationToken)); return ImmutableArray.CreateRange(await query(Tokens).ToListAsync(cancellationToken));
} }
/// <summary> /// <summary>

Loading…
Cancel
Save