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_r262293712
 
 

 ##########
 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:
   Updated benchmarking:
   
   ```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
   
   def fun3(data):
       a=set()
       a.update({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(fun2(list(range(100)) + list(range(100))) == fun3(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"))
       print(timeit.timeit("fun3(list(range(300)) + list(range(300)))", 
setup="from __main__ import fun3"))
   ```
   
   Result:
   True
   True
   51.447706788999994
   26.681957754999985
   26.59145899200007
   

----------------------------------------------------------------
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

Reply via email to