Unverified Commit a447a0a9 authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #155 from jumpserver/bugfix

[Bugfix] 修复搜索时失败
parents 9591d717 4d393acd
...@@ -43,7 +43,7 @@ class InteractiveServer: ...@@ -43,7 +43,7 @@ class InteractiveServer:
self.total_count = 0 # 分页展示中的资产总数量 self.total_count = 0 # 分页展示中的资产总数量
self.node_tree = None # 授权节点树 self.node_tree = None # 授权节点树
self.load_user_assets_from_cache() self.load_user_assets_from_cache()
self.get_user_assets_async() self.get_user_assets_and_update_async()
self.get_user_nodes_async() self.get_user_nodes_async()
@property @property
...@@ -162,10 +162,16 @@ class InteractiveServer: ...@@ -162,10 +162,16 @@ class InteractiveServer:
self.display_assets_paging(assets) self.display_assets_paging(assets)
def refresh_assets_nodes(self): def refresh_assets_nodes(self):
self.get_user_assets_async() self.get_user_assets_and_update_async()
self.get_user_nodes_async() self.get_user_nodes_async()
def wait_until_assets_load(self):
while self.assets is None and \
self.get_user_assets_finished is False:
time.sleep(0.2)
def search_assets(self, q): def search_assets(self, q):
self.wait_until_assets_load()
result = [] result = []
# 所有的 # 所有的
...@@ -194,10 +200,8 @@ class InteractiveServer: ...@@ -194,10 +200,8 @@ class InteractiveServer:
# #
def display_assets(self): def display_assets(self):
while self.assets is None and not self.get_user_assets_finished: self.wait_until_assets_load()
time.sleep(0.5) self.display_assets_paging(self.assets)
if self.assets:
self.display_assets_paging(self.assets)
def display_assets_paging(self, assets): def display_assets_paging(self, assets):
if len(assets) == 0: if len(assets) == 0:
...@@ -318,17 +322,14 @@ class InteractiveServer: ...@@ -318,17 +322,14 @@ class InteractiveServer:
if assets: if assets:
self.total_asset_count = len(assets) self.total_asset_count = len(assets)
def set_user_assets_cache(self, assets): def get_user_assets_and_update_async(self):
self.__class__._user_assets_cached[self.client.user.id] = assets thread = threading.Thread(target=self.get_user_assets_and_update)
def get_user_assets_async(self):
thread = threading.Thread(target=self.get_user_assets)
thread.start() thread.start()
def get_user_assets(self): def get_user_assets_and_update(self):
assets = app_service.get_user_assets(self.client.user) assets = app_service.get_user_assets(self.client.user)
assets = self.filter_system_users(assets) assets = self.filter_system_users(assets)
self.set_user_assets_cache(assets) self.__class__._user_assets_cached[self.client.user.id] = assets
self.load_user_assets_from_cache() self.load_user_assets_from_cache()
self.get_user_assets_finished = True self.get_user_assets_finished = True
# #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment