Skip to content

Conversation

@AlanCoding
Copy link
Member

@AlanCoding AlanCoding commented Sep 15, 2025

Description

This does general, obligatory, optimizations of API endpoints that were recently added.

The largest code change is because using LARGE=true with the bootstrap script wasn't creating all the RBAC objects, additional logic to do so was added. This did help to test cases of >25 Role definitions, role-user-assignments, and role-team-assignments.

This work is basically never-ending, so any stopping point is arbitrary. However, the new /service-index/ views greatly benefit from this.

The found solution often repeated for resource__content_type also suggests that the resource summary_fields entry is generally not well-optimized, because it's unlikely someone would have continued that to include __content_type.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test update
  • Refactoring (no functional changes)
  • Development environment change
  • Configuration change

Note

Improves RBAC and service-index performance via queryset prefetching, permission caching, and ansible_id annotations; refactors serializers for ansible_id handling; and expands LARGE demo data with roles/assignments plus comprehensive tests.

  • Performance/Query Optimizations:
    • Activity Stream: prefetch created_by, content_type in EntryReadOnlyViewSet.
    • RBAC API: cache permission lookups in RoleMetadataView; prefetch resource on RoleDefinition queryset; prefetch team__resource and user__resource in assignment viewsets.
    • Service API: annotate _object_ansible_id_annotation via Subquery on Resource; prefetch __resource__content_type for users/teams.
    • Resource Registry: use content_type_id for resource_type accessors.
  • Serializer Refactor:
    • Replace ObjectIDAnsibleIDField with ObjectAnsibleIdField supporting annotation-based reads and ansible_id→object_id conversion; simplify to_representation and update validation to accept either object_id or object_ansible_id.
  • Demo Data (LARGE mode):
    • Generate roledefinition records with DABPermissions; assign >25 permissions to users/teams; fix team-to-org linkage; add DEMO_DATA_COUNTS['roledefinition'].
  • Tests:
    • Add validation error cases (system role/object requirements) and created_by_ansible_id null handling.
    • Add N+1 avoidance/performance tests for summary_fields across models.
    • Add LARGE-mode demo data assertions (counts, permissions, assignments).

Written by Cursor Bugbot for commit 19dbde1. This will update automatically on new commits. Configure here.

@AlanCoding AlanCoding marked this pull request as ready for review September 17, 2025 18:24
@AlanCoding
Copy link
Member Author

In terms of the code coverage, that's low because of added test_app to create demo data. I don't want this counted in code coverage, at all.

@AlanCoding AlanCoding changed the title AAP-53611 General API optimizations for RBAC AAP-53278 General API optimizations for RBAC Oct 6, 2025
cursor[bot]

This comment was marked as outdated.

@github-actions
Copy link

DVCS PR Check Results:

PR appears valid (JIRA key(s) found)

@sonarqubecloud
Copy link

@AlanCoding AlanCoding requested a review from fosterseth October 23, 2025 15:01
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 this pull request may close these issues.

3 participants