浏览代码

HUE-8817 [core] Improve get_ordered_interpreters performance

(cherry picked from commit 55fc1d3fe1e59336608dcfb983d427333e49b509)
jdesjean 6 年之前
父节点
当前提交
6cea9c74d7
共有 1 个文件被更改,包括 5 次插入3 次删除
  1. 5 3
      desktop/libs/notebook/src/notebook/conf.py

+ 5 - 3
desktop/libs/notebook/src/notebook/conf.py

@@ -35,8 +35,9 @@ SHOW_NOTEBOOKS = Config(
 def _remove_duplications(a_list):
 def _remove_duplications(a_list):
   return list(OrderedDict.fromkeys(a_list))
   return list(OrderedDict.fromkeys(a_list))
 
 
-def check_permissions(user, interpreter):
-  user_apps = appmanager.get_apps_dict(user)
+def check_permissions(user, interpreter, user_apps=None):
+  if user_apps is None:
+    user_apps = appmanager.get_apps_dict(user) # Expensive method
   return (interpreter == 'hive' and 'hive' not in user_apps) or \
   return (interpreter == 'hive' and 'hive' not in user_apps) or \
          (interpreter == 'impala' and 'impala' not in user_apps) or \
          (interpreter == 'impala' and 'impala' not in user_apps) or \
          (interpreter == 'pig' and 'pig' not in user_apps) or \
          (interpreter == 'pig' and 'pig' not in user_apps) or \
@@ -56,9 +57,10 @@ def get_ordered_interpreters(user=None):
   interpreters = INTERPRETERS.get()
   interpreters = INTERPRETERS.get()
   interpreters_shown_on_wheel = _remove_duplications(INTERPRETERS_SHOWN_ON_WHEEL.get())
   interpreters_shown_on_wheel = _remove_duplications(INTERPRETERS_SHOWN_ON_WHEEL.get())
 
 
+  user_apps = appmanager.get_apps_dict(user)
   user_interpreters = []
   user_interpreters = []
   for interpreter in interpreters:
   for interpreter in interpreters:
-    if check_permissions(user, interpreter):
+    if check_permissions(user, interpreter, user_apps=user_apps):
       pass # Not allowed
       pass # Not allowed
     else:
     else:
       user_interpreters.append(interpreter)
       user_interpreters.append(interpreter)