Optimize composite role evaluation#13146
Conversation
|
This PR shows a decent way to optimize role evaluation. |
| Set<MapRoleEntity> result = new HashSet<>(); | ||
| @SuppressWarnings("unchecked") List<String> sqlResult = (List<String>) nativeQuery.getResultList(); | ||
| for (String targetRole : targetRoles) { | ||
| result.add(read(targetRole)); | ||
| } | ||
| for (String targetRole : sqlResult) { | ||
| result.add(read(targetRole)); | ||
| } | ||
| return result; |
There was a problem hiding this comment.
Would it make sense to use criteria() instead of for loops?
| Set<MapRoleEntity> result = new HashSet<>(); | |
| @SuppressWarnings("unchecked") List<String> sqlResult = (List<String>) nativeQuery.getResultList(); | |
| for (String targetRole : targetRoles) { | |
| result.add(read(targetRole)); | |
| } | |
| for (String targetRole : sqlResult) { | |
| result.add(read(targetRole)); | |
| } | |
| return result; | |
| @SuppressWarnings("unchecked") List<String> sqlResult = (List<String>) nativeQuery.getResultList(); | |
| targetRoles.addAll(sqlResult); | |
| DefaultModelCriteria<RoleModel> mcb = criteria(); | |
| mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realmId) | |
| .compare(SearchableFields.ID, Operator.IN, targetRoles); | |
| return read(withCriteria(mcb)).collect(Collectors.toSet()); |
note: if it'll be decided to return Stream, then return statement could loo like: return read(withCriteria(mcb));
| return getAttributes().getOrDefault(name, Collections.EMPTY_LIST).stream(); | ||
| } | ||
|
|
||
| public RealmModel getRealm() { |
There was a problem hiding this comment.
The method could be probably introduced in RoleModel as the "other" models also has access to the RealmModel as well. This way it could be avoided to cast RoleModel to MapRoleAdapter in MapRoleProvider.
@hmlnarik I'm not sure whether this can be postponed too much as the RoleModel is located in server-spi package and I'm not sure if we would be able to change it in future.
|
|
||
| boolean hasRole(String realmId, Set<String> roleIds, Set<String> targetRoleIds); | ||
|
|
||
| Set<V> expandCompositeRoles(String realmId, Set<String> targetRoles); |
There was a problem hiding this comment.
If the Stream would be returned we might get rid of some collecting-and-then-making-stream-again.
| Set<V> expandCompositeRoles(String realmId, Set<String> targetRoles); | |
| Stream<V> expandCompositeRoles(String realmId, Set<String> targetRoles); |
|
Closing this one as obsolete as there is no more map store. |
Closes #12888