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_r262117922
##########
File path: airflow/www/security.py
##########
@@ -233,8 +233,8 @@ def get_all_permissions_views(self):
"""
perms_views = set()
for role in self.get_user_roles():
- for perm_view in role.permissions:
- perms_views.add((perm_view.permission.name,
perm_view.view_menu.name))
+ perms_views = perms_views | {(perm_view.permission.name,
perm_view.view_menu.name)
+ for perm_view in role.permissions}
Review comment:
```python
def fun1(data):
a=set()
for d in data:
a.add(d)
return a
def fun2(data):
a=set()
a = a | {d for d in data}
return a
if __name__ == '__main__':
import timeit
print(fun1(list(range(100)) + list(range(100))) == fun2(list(range(100))
+ list(range(100))))
print(timeit.timeit("fun1(list(range(300)) + list(range(300)))",
setup="from __main__ import fun1"))
print(timeit.timeit("fun2(list(range(300)) + list(range(300)))",
setup="from __main__ import fun2"))
```
Result:
True
52.7378087699999
27.333367159999398
----------------------------------------------------------------
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