Skip to content

Commit c6f3810

Browse files
authored
refactor(SyncCache): simplify ResetAsync method (#750)
Replaced the `ClientQueryAsync` method with `ClientQuery().ToListAsync()` in the `ResetAsync` implementation. The `ClientQueryAsync` method and its internal logic have been removed, streamlining the asynchronous query process and improving code readability and maintainability.
1 parent 618fe45 commit c6f3810

File tree

1 file changed

+1
-31
lines changed
  • src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.EFCore/Caches

1 file changed

+1
-31
lines changed

src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.EFCore/Caches/SyncCache.cs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public async Task ResetAsync()
9393
{
9494
if (_clientCache is not null)
9595
{
96-
var clients = await ClientQueryAsync();
96+
var clients = await ClientQuery().ToListAsync();
9797
await _clientCache.ResetAsync(clients);
9898
}
9999
if (_apiScopeCache is not null)
@@ -113,36 +113,6 @@ public async Task ResetAsync()
113113
}
114114
}
115115

116-
[ExcludeFromCodeCoverage]
117-
public async Task<IEnumerable<Client>> ClientQueryAsync()
118-
{
119-
var clients = await _context.Set<Client>().ToListAsync();
120-
var clientPropertys = await _context.Set<ClientProperty>().ToListAsync();
121-
var clientClaims = await _context.Set<ClientClaim>().ToListAsync();
122-
var clientIdPRestrictions = await _context.Set<ClientIdPRestriction>().ToListAsync();
123-
var clientCorsOrigins = await _context.Set<ClientCorsOrigin>().ToListAsync();
124-
var clientSecrets = await _context.Set<ClientSecret>().ToListAsync();
125-
var clientGrantTypes = await _context.Set<ClientGrantType>().ToListAsync();
126-
var clientRedirectUris = await _context.Set<ClientRedirectUri>().ToListAsync();
127-
var clientPostLogoutRedirectUris = await _context.Set<ClientPostLogoutRedirectUri>().ToListAsync();
128-
var clientScopes = await _context.Set<ClientScope>().ToListAsync();
129-
130-
foreach (var client in clients)
131-
{
132-
client.AllowedGrantTypes.AddRange(clientGrantTypes.Where(item => item.ClientId == client.Id));
133-
client.RedirectUris.AddRange(clientRedirectUris.Where(item => item.ClientId == client.Id));
134-
client.PostLogoutRedirectUris.AddRange(clientPostLogoutRedirectUris.Where(item => item.ClientId == client.Id));
135-
client.Properties.AddRange(clientPropertys.Where(item => item.ClientId == client.Id));
136-
client.Claims.AddRange(clientClaims.Where(item => item.ClientId == client.Id));
137-
client.IdentityProviderRestrictions.AddRange(clientIdPRestrictions.Where(item => item.ClientId == client.Id));
138-
client.AllowedCorsOrigins.AddRange(clientCorsOrigins.Where(item => item.ClientId == client.Id));
139-
client.ClientSecrets.AddRange(clientSecrets.Where(item => item.ClientId == client.Id));
140-
client.AllowedScopes.AddRange(clientScopes.Where(item => item.ClientId == client.Id));
141-
}
142-
143-
return clients;
144-
}
145-
146116
private IQueryable<IdentityResource> IdentityResourceQuery()
147117
{
148118
return _context.Set<IdentityResource>()

0 commit comments

Comments
 (0)