bito-code-review[bot] commented on PR #44905:
URL: https://github.com/apache/superset/pull/44905#issuecomment-5962339761
<!-- Bito Reply -->
The flagged performance issue is correct. The current implementation of
`semantic_layer_before_delete` performs a database query for every child view
to check if its permission is owned elsewhere, leading to O(n) round trips.
To resolve this, you can optimize the permission ownership check by batching
the queries. Instead of querying for each view individually, you can fetch all
relevant permissions in a single query or use a more efficient set-based
approach to identify which permissions are still in use by other resources.
**superset/security/manager.py**
```
def _semantic_view_perm_owned_elsewhere(
self,
connection: Connection,
perm: str,
deleted_view_ids: set[int],
) -> bool:
# ... (existing logic)
# Optimization: Consider fetching all used permissions in one query
# and checking against that set instead of querying per-permission.
return (
connection.execute(
sv_table.select()
.where(sv_table.c.perm == perm,
sv_table.c.id.not_in(deleted_view_ids))
.limit(1)
).first()
is not None
)
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]