Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using implicit joins in FindAuthorizationAsync #51

Open
mentaldriller opened this issue Jul 10, 2023 · 0 comments · May be fixed by #55
Open

Using implicit joins in FindAuthorizationAsync #51

mentaldriller opened this issue Jul 10, 2023 · 0 comments · May be fixed by #55

Comments

@mentaldriller
Copy link

mentaldriller commented Jul 10, 2023

In method FindAuthorizationSync in Balea.EntityFramework.Store, I found that using Joins via "Include" method causes performance issues in the resulting query, especially when there is intensive data reads. My suggestion is to modify the method to use implicit joins as follows:

public async Task<AuthorizationContext> FindAuthorizationAsync(ClaimsPrincipal user, CancellationToken cancellationToken = default) { var sourceRoleClaims = user.GetClaimValues(_options.DefaultClaimTypeMap.RoleClaimType); var delegation = await _context.Delegations.GetCurrentDelegation( user.GetUserId(_options), _options.ApplicationName, cancellationToken); var subject = GetSubject(user, delegation); var roles = await _context.Roles .AsNoTracking() .Where(role => role.Application.Name == _options.ApplicationName && role.Enabled && (role.Users.Any(rs => rs.User.Sub == subject) || role.Mappings.Any(rm => sourceRoleClaims.Contains(rm.Mapping.Name))) ).Select(r => new Role(r.Name, r.Description, r.Users.Select(rs => rs.User.Sub), r.Mappings.Select(rm => rm.Mapping.Name), r.Permissions.Select(rp => rp.Permission.Value), r.Enabled)) .ToListAsync(cancellationToken); return new AuthorizationContext(roles, delegation.To()); }

@pbr1111 pbr1111 linked a pull request Sep 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant