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

IBX-5663: Added paginated role assignments load method to API #373

Merged
merged 25 commits into from
Jun 19, 2023

Conversation

barw4
Copy link
Member

@barw4 barw4 commented May 15, 2023

Question Answer
JIRA issue IBX-5663
Type feature
Target Ibexa version v3.3
BC breaks no

2 new methods were added to RoleService in order to improve performance in the Back Office:

  • loadRoleAssignments - allows setting $offset and $limit arguments in order to allow pagination. The old method getRoleAssignments even if cached could result in a huge performance drop in the Back Office as the amount of assignments can be really large.
  • countRoleAssignments - counting role assignments, usable for the above method.

Related PR: ezsystems/ezplatform-admin-ui#2102

Checklist:

  • Provided PR description.
  • Tested the solution manually.
  • Provided automated test coverage.
  • Checked that target branch is set correctly (master for features, the oldest supported for bugs).
  • Ran PHP CS Fixer for new PHP code (use $ composer fix-cs).
  • Asked for a review (ping @ezsystems/engineering-team).

@ViniTou
Copy link
Contributor

ViniTou commented May 16, 2023

Is there a possibility to use proxies for policies instead of introducing a new method and later thinking why there are nulls for some cases?

@barw4
Copy link
Member Author

barw4 commented May 16, 2023

@ViniTou I'll take a look into it.

Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a business logic and security issues here. Currently there's no way to distinguish between a Role without policies from a Role without loaded policies. From API contract perspective information returned like that is not correct and could lead to treating the object as policy-less one, leading to security holes in places where we forgot or 3rd party is not aware that the information loaded is not full.

Is there a possibility to use proxies for policies instead of introducing a new method and later thinking why there are null for some cases?

Seems like the most reasonable way.

@barw4
Copy link
Member Author

barw4 commented May 17, 2023

@alongosz @ViniTou as policies property in Role is an array and assuming we don't want to change that how would you want to approach building a proxy? ProxyGenerator requires an actual object to be proxied, so would you like to proxy every policy separately? It would require fetching ids of those policies either way so performance gain would be minimal.

@ViniTou
Copy link
Contributor

ViniTou commented May 17, 2023

@barw4
ArrayObject wouldnt probably be some solution, as I am almost sure it would fail at some level, and I think it will count as BC.

Other way, would be to introduce new class for that Role without policies, but probably above will apply as well.
Atm, no other ideas that wouldnt be some __get hacking things, but in current state I agree this is no go - it creates more problems than it resolves.

Is adding just pagination for role assigments not enough?

@barw4
Copy link
Member Author

barw4 commented May 17, 2023

@ViniTou it should suffice for now, at least according to the public ticket. I've removed listRoles.

@barw4 barw4 requested a review from ViniTou May 17, 2023 15:47
@barw4 barw4 changed the title IBX-5663: Added paginated role assignments load and roles without policies methods to API IBX-5663: Added paginated role assignments load method to API May 17, 2023
Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is a good direction 💪
It needs a little bit of improvement:

eZ/Publish/API/Repository/RoleService.php Outdated Show resolved Hide resolved
eZ/Publish/API/Repository/Tests/RoleServiceTest.php Outdated Show resolved Hide resolved
eZ/Publish/API/Repository/Tests/RoleServiceTest.php Outdated Show resolved Hide resolved
eZ/Publish/Core/Repository/RoleService.php Show resolved Hide resolved
eZ/Publish/Core/Repository/RoleService.php Outdated Show resolved Hide resolved
eZ/Publish/Core/Repository/RoleService.php Show resolved Hide resolved
eZ/Publish/Core/Persistence/Cache/UserHandler.php Outdated Show resolved Hide resolved
@barw4 barw4 requested review from alongosz and a team May 19, 2023 12:44
@barw4 barw4 requested a review from Steveb-p May 22, 2023 14:45
@barw4 barw4 requested review from alongosz and a team June 1, 2023 09:50
@barw4 barw4 requested a review from alongosz June 2, 2023 13:00
Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: persistence cache for countRoleAssignments method was not implemented on purpose after a discovery phase and going back and forth on the solution.
It's because backoffice uses Trash and Content API to trash and then delete User Group, instead of User API. This makes role to user group assignment cache for count impossible to invalidate in a clean way.

We need to take another iteration to solve this separately, most likely after 4.6.0 LTS release.

@sonarcloud
Copy link

sonarcloud bot commented Jun 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 6 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@micszo micszo self-assigned this Jun 15, 2023
Copy link
Member

@micszo micszo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced the 30 seconds execution timeout with ca. 6k assigned users. Problem was occurring with new cache. Consecutive reloads took 7-8 seconds.
With the fix such role loads like any standard role, in 1-2 seconds in a dev env.

QA Approved on Ibexa Experience 3.3.34-dev with diffs.

@micszo micszo removed their assignment Jun 16, 2023
@alongosz alongosz merged commit 0b8bad6 into 1.3 Jun 19, 2023
24 checks passed
@alongosz alongosz deleted the ibx-5663-loading-role-assignments-paginated branch June 19, 2023 09:11
@alongosz
Copy link
Member

Nice work @barw4 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request QA approved
9 participants