Skip to content

Using implicit joins in FindAuthorizationAsync #51

@mentaldriller

Description

@mentaldriller

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()); }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions