In the current implementation, every time we have to upsert a privilege or retrieve a role by lookupKey, we call the method retrieveStorageContextByCode provided by the RolesService (microservice). This method perform the following steps:
retrieve the role identified by lookupKey
if the role has extendedRoleIds, it performs an additional query for each extended role id
if the extended role has extendedRoleIds, repeat step 2 and 3 (recursion)
Note: steps 2 and 3 are executed sequentially
Currently the max depth for extended roles is 2:
organization-admin/owner โ space-supervisor โ space-folder, course-observerThis means executing up to 2 queries for each extended role.

In order to avoid this amount of queries, we can refactor the method by leveraging population ($lookup). This way we will perform a single query.

Note: if we want to support more than 2 levels of inheritance, we can adjust the method like this:
retrieve role and populate up to the second level
if second-level roles have extendedRoleIds, collect role ids and repeat step 1 on them (using find instead of findOne)
repeat until second-level roles have no extendedRoleIds
Please authenticate to join the conversation.
Completed
Bug & Fixes
High Priority
11 months ago

Ivan Ligotino
Get notified by email when there are changes.
Completed
Bug & Fixes
High Priority
11 months ago

Ivan Ligotino
Get notified by email when there are changes.