ashb commented on code in PR #22858:
URL: https://github.com/apache/airflow/pull/22858#discussion_r846295180
##########
airflow/www/fab_security/sqla/models.py:
##########
@@ -229,10 +229,24 @@ def is_anonymous(self):
@property
def perms(self):
- perms = set()
- for role in self.roles:
- perms.update((perm.action.name, perm.resource.name) for perm in
role.permissions)
- return perms
+ if not self._perms_cache:
+ # Using the ORM here is _slow_ (Creating lots of objects to then
throw them away) since this is in
+ # the path for every request. Avoid it if we can!
+ if current_app:
+ sm = current_app.appbuilder.sm
+ self._perms_cache: Set[Tuple[str, str]] = set(
+ sm.get_session.query(sm.action_model.name,
sm.resource_model.name)
+ .join(sm.permission_model.action)
+ .join(sm.permission_model.resource)
+ .join(sm.permission_model.role)
+ .filter(sm.role_model.user.contains(g.user))
Review Comment:
```suggestion
.filter(sm.role_model.user.contains(self))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]