### Apache Airflow version

2.5.0

### What happened

We're currently running a suboptimal setup where database connectivity is laggy, 125ms roundtrip.

This has interesting consequences. For example, `airflow roles list` is really slow. Turns out that it's doing a lot of individual queries.

### What you think should happen instead

Ideally, listing roles should be a single (perhaps complex) query.

### How to reproduce

We're using py-spy to sample program execution:

```bash
$ py-spy record -o spy.svg -i --rate 250 --nonblocking airflow roles list
```
Now, to see the bad behavior, the database should incur significant latency.

### Operating System

Linux

### Versions of Apache Airflow Providers

_No response_

### Deployment

Official Apache Airflow Helm Chart

### Deployment details

_No response_

### Anything else

_No response_

### Are you willing to submit PR?

- [ ] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)

"""Deletes role in DB."""
    appbuilder = cached_app().appbuilder
    for role_name in args.role:
        role = appbuilder.sm.find_role(role_name)
        if not role:
            print(f"Role named '{role_name}' does not exist")
            exit(1)
    for role_name in args.role:
        appbuilder.sm.delete_role(role_name)
    print(f"Deleted {len(args.role)} role(s)")
def __roles_add_or_remove_permissions(args):
    asm: AirflowSecurityManager = cached_app().appbuilder.sm
    is_add: bool = args.subcommand.startswith("add")
    role_map = {}
    perm_map: dict[tuple[str, str], set[str]] = collections.defaultdict(set)
    for name in args.role:
        role: Role | None = asm.find_role(name)
        if not role:
            print(f"Role named '{name}' does not exist")
            exit(1)
        role_map[name] = role
        for permission in role.permissions:
            perm_map[(name, permission.resource.name)].add(permission.action.name)