XD-DENG commented on a change in pull request #4833: [AIRFLOW-4006] Make better
use of Set in AirflowSecurityManager
URL: https://github.com/apache/airflow/pull/4833#discussion_r262117624
##########
File path: airflow/www/security.py
##########
@@ -185,11 +185,11 @@ def init_role(self, role_name, role_vms, role_perms):
if len(role.permissions) == 0:
self.log.info('Initializing permissions for role:%s in the
database.', role_name)
- role_pvms = []
+ role_pvms = set()
for pvm in pvms:
if pvm.view_menu.name in role_vms and pvm.permission.name in
role_perms:
- role_pvms.append(pvm)
- role.permissions = list(set(role_pvms))
+ role_pvms.add(pvm)
+ role.permissions = list(role_pvms)
Review comment:
```python
def fun1(data):
a=[]
for d in data:
a.append(d)
return list(set(a))
def fun2(data):
a=set()
for d in data:
a.add(d)
return list(a)
if __name__ == '__main__':
import timeit
print(timeit.timeit("fun1(list(range(100)) + list(range(100)))",
setup="from __main__ import fun1"))
print(timeit.timeit("fun2(list(range(100)) + list(range(100)))",
setup="from __main__ import fun2"))
```
result:
22.5804829597
18.7606010437
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services