Remove redundant db calls in PermissionService#2696
Merged
crivetimihai merged 1 commit intomainfrom Feb 7, 2026
Merged
Conversation
8156853 to
dc95145
Compare
Closes #2695 - check_permission() now calls _get_user_roles() once and reuses results for both permission extraction and audit logging (was calling get_user_permissions then _get_roles_for_audit separately) - _check_team_fallback_permissions() uses _get_user_team_role() directly instead of calling _is_team_member() then _get_user_team_role() - _is_team_member() delegates to _get_user_team_role() for backward compat - Remove now-unused _get_roles_for_audit() method - Update tests to mock _get_user_roles instead of get_user_permissions Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
dc95145 to
b678a59
Compare
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
Closes IBM#2695 - check_permission() now calls _get_user_roles() once and reuses results for both permission extraction and audit logging (was calling get_user_permissions then _get_roles_for_audit separately) - _check_team_fallback_permissions() uses _get_user_team_role() directly instead of calling _is_team_member() then _get_user_team_role() - _is_team_member() delegates to _get_user_team_role() for backward compat - Remove now-unused _get_roles_for_audit() method - Update tests to mock _get_user_roles instead of get_user_permissions Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug-fix PR
Closes #2695
Summary
Fixes redundant database queries in
PermissionService.check_permission()that caused unnecessary performance overhead on every permission check.Two separate redundancies were identified and fixed:
Reproduction Steps
Issue: Redundant DB calls in permission checks
To observe the issue:
check_permission()withaudit_enabled=TrueSELECTstatements foruser_rolesandemail_team_memberstablesRoot Cause
Redundancy #1 (UserRole):
check_permission()calledget_user_permissions()which internally called_get_user_roles()to fetch UserRole objectsget_user_permissions()extracted only the permission strings and discarded the role objects_get_roles_for_audit()called_get_user_roles()again to get role names for audit loggingRedundancy #2 (EmailTeamMember):
_check_team_fallback_permissions()called_is_team_member()to check if user was a team member_get_user_team_role()to get the user's roleemail_team_memberstable with identical filtersFix Description
Fix #1: Modified
check_permission()to:_get_user_roles()directly onceFix #2: Modified
_check_team_fallback_permissions()to:_get_user_team_role()which returnsNoneif not a memberNoneinstead of separate membership query_is_team_member()to delegate to_get_user_team_role()for backward compatibilityDB Call Reduction:
Verification
make lintmake testmake coverageMCP Compliance (if relevant)
Checklist
make black isort pre-commit)_get_user_rolesinstead ofget_user_permissions