Commit 97865db8 authored by ibuler's avatar ibuler

[Update] 支持缓存

parent 56630b9e
...@@ -135,7 +135,6 @@ class InteractiveServer: ...@@ -135,7 +135,6 @@ class InteractiveServer:
self.display_banner() self.display_banner()
elif opt in ['r', 'R']: elif opt in ['r', 'R']:
self.refresh_assets_nodes() self.refresh_assets_nodes()
self.display_banner()
elif opt in ['h', 'H']: elif opt in ['h', 'H']:
self.display_banner() self.display_banner()
else: else:
...@@ -165,8 +164,9 @@ class InteractiveServer: ...@@ -165,8 +164,9 @@ 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_and_update_async() self.get_user_assets_and_update(cache_policy='2')
self.get_user_nodes_async() self.get_user_nodes(cache_policy='2')
self.client.send_unicode(_("Refresh done"))
def wait_until_assets_load(self): def wait_until_assets_load(self):
while self.assets is None and \ while self.assets is None and \
...@@ -319,9 +319,7 @@ class InteractiveServer: ...@@ -319,9 +319,7 @@ class InteractiveServer:
# #
def load_user_assets_from_cache(self): def load_user_assets_from_cache(self):
assets = self.__class__._user_assets_cached.get( assets = self.__class__._user_assets_cached.get(self.client.user.id)
self.client.user.id
)
self.assets = assets self.assets = assets
if assets: if assets:
self.total_asset_count = len(assets) self.total_asset_count = len(assets)
...@@ -330,8 +328,8 @@ class InteractiveServer: ...@@ -330,8 +328,8 @@ class InteractiveServer:
thread = threading.Thread(target=self.get_user_assets_and_update) thread = threading.Thread(target=self.get_user_assets_and_update)
thread.start() thread.start()
def get_user_assets_and_update(self): def get_user_assets_and_update(self, cache_policy='1'):
assets = app_service.get_user_assets(self.client.user) assets = app_service.get_user_assets(self.client.user, cache_policy=cache_policy)
assets = self.filter_system_users(assets) assets = self.filter_system_users(assets)
self.__class__._user_assets_cached[self.client.user.id] = assets self.__class__._user_assets_cached[self.client.user.id] = assets
self.load_user_assets_from_cache() self.load_user_assets_from_cache()
...@@ -344,8 +342,8 @@ class InteractiveServer: ...@@ -344,8 +342,8 @@ class InteractiveServer:
thread = threading.Thread(target=self.get_user_nodes) thread = threading.Thread(target=self.get_user_nodes)
thread.start() thread.start()
def get_user_nodes(self): def get_user_nodes(self, cache_policy='1'):
nodes = app_service.get_user_asset_groups(self.client.user) nodes = app_service.get_user_asset_groups(self.client.user, cache_policy=cache_policy)
nodes = sorted(nodes, key=lambda node: node.key) nodes = sorted(nodes, key=lambda node: node.key)
self.nodes = self.filter_system_users_of_assets_under_nodes(nodes) self.nodes = self.filter_system_users_of_assets_under_nodes(nodes)
self._construct_node_tree() self._construct_node_tree()
......
...@@ -7,7 +7,7 @@ msgid "" ...@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-02-21 20:00+0800\n" "POT-Creation-Date: 2019-03-06 14:51+0800\n"
"PO-Revision-Date: 2018-08-10 10:42+0800\n" "PO-Revision-Date: 2018-08-10 10:42+0800\n"
"Last-Translator: BaiJiangjie <bugatti_it@163.com>\n" "Last-Translator: BaiJiangjie <bugatti_it@163.com>\n"
"Language-Team: Language locale/en/LC\n" "Language-Team: Language locale/en/LC\n"
...@@ -16,7 +16,7 @@ msgstr "" ...@@ -16,7 +16,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: coco/app.py:180 #: coco/app.py:182
msgid "Connect idle more than {} minutes, disconnect" msgid "Connect idle more than {} minutes, disconnect"
msgstr "" msgstr ""
...@@ -83,10 +83,14 @@ msgstr "" ...@@ -83,10 +83,14 @@ msgstr ""
msgid "{T}0) Enter {green}q{end} exit.{R}" msgid "{T}0) Enter {green}q{end} exit.{R}"
msgstr "" msgstr ""
#: coco/interactive.py:159 #: coco/interactive.py:158
msgid "Terminal does not support login rdp, please use web terminal to access" msgid "Terminal does not support login rdp, please use web terminal to access"
msgstr "" msgstr ""
#: coco/interactive.py:169
msgid "Refresh done"
msgstr ""
#: coco/interactive.py:211 #: coco/interactive.py:211
msgid "No Assets" msgid "No Assets"
msgstr "" msgstr ""
...@@ -131,27 +135,27 @@ msgstr "" ...@@ -131,27 +135,27 @@ msgstr ""
msgid "BACK: b/q" msgid "BACK: b/q"
msgstr "" msgstr ""
#: coco/interactive.py:373 #: coco/interactive.py:371
msgid "No Nodes" msgid "No Nodes"
msgstr "" msgstr ""
#: coco/interactive.py:377 #: coco/interactive.py:375
msgid "Node: [ ID.Name(Asset amount) ]" msgid "Node: [ ID.Name(Asset amount) ]"
msgstr "" msgstr ""
#: coco/interactive.py:379 #: coco/interactive.py:377
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1" msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgstr "" msgstr ""
#: coco/interactive.py:387 #: coco/interactive.py:385
msgid "There is no matched node, please re-enter" msgid "There is no matched node, please re-enter"
msgstr "" msgstr ""
#: coco/interactive.py:417 #: coco/interactive.py:415
msgid "Select a login:: " msgid "Select a login:: "
msgstr "" msgstr ""
#: coco/interactive.py:440 #: coco/interactive.py:438
msgid "No system user" msgid "No system user"
msgstr "" msgstr ""
......
...@@ -7,7 +7,7 @@ msgid "" ...@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-02-21 20:00+0800\n" "POT-Creation-Date: 2019-03-06 14:51+0800\n"
"PO-Revision-Date: 2018-08-10 10:42+0800\n" "PO-Revision-Date: 2018-08-10 10:42+0800\n"
"Last-Translator: BaiJiangjie <bugatti_it@163.com>\n" "Last-Translator: BaiJiangjie <bugatti_it@163.com>\n"
"Language-Team: Language locale/zh\n" "Language-Team: Language locale/zh\n"
...@@ -16,7 +16,7 @@ msgstr "" ...@@ -16,7 +16,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: coco/app.py:180 #: coco/app.py:182
msgid "Connect idle more than {} minutes, disconnect" msgid "Connect idle more than {} minutes, disconnect"
msgstr "空闲时间超过 {} 分钟,断开连接" msgstr "空闲时间超过 {} 分钟,断开连接"
...@@ -25,6 +25,7 @@ msgid "Welcome to use Jumpserver open source fortress system" ...@@ -25,6 +25,7 @@ msgid "Welcome to use Jumpserver open source fortress system"
msgstr "欢迎使用Jumpserver开源跳板机系统" msgstr "欢迎使用Jumpserver开源跳板机系统"
#: coco/interactive.py:87 #: coco/interactive.py:87
#, python-brace-format
msgid "" msgid ""
"\n" "\n"
"{T}{T}{title} {user}, {header_title} {end}{R}{R}" "{T}{T}{title} {user}, {header_title} {end}{R}{R}"
...@@ -89,10 +90,14 @@ msgstr "{T}0) 输入 {green}r{end} 刷新最新的机器和节点信息.{R}" ...@@ -89,10 +90,14 @@ msgstr "{T}0) 输入 {green}r{end} 刷新最新的机器和节点信息.{R}"
msgid "{T}0) Enter {green}q{end} exit.{R}" msgid "{T}0) Enter {green}q{end} exit.{R}"
msgstr "{T}0) 输入 {green}q{end} 退出.{R}" msgstr "{T}0) 输入 {green}q{end} 退出.{R}"
#: coco/interactive.py:159 #: coco/interactive.py:158
msgid "Terminal does not support login rdp, please use web terminal to access" msgid "Terminal does not support login rdp, please use web terminal to access"
msgstr "终端不支持登录windows, 请使用web terminal访问" msgstr "终端不支持登录windows, 请使用web terminal访问"
#: coco/interactive.py:169
msgid "Refresh done"
msgstr "刷新完成"
#: coco/interactive.py:211 #: coco/interactive.py:211
msgid "No Assets" msgid "No Assets"
msgstr "没有资产" msgstr "没有资产"
...@@ -137,27 +142,27 @@ msgstr "下一页: Enter|N/n" ...@@ -137,27 +142,27 @@ msgstr "下一页: Enter|N/n"
msgid "BACK: b/q" msgid "BACK: b/q"
msgstr "返回: B/b" msgstr "返回: B/b"
#: coco/interactive.py:373 #: coco/interactive.py:371
msgid "No Nodes" msgid "No Nodes"
msgstr "没有节点" msgstr "没有节点"
#: coco/interactive.py:377 #: coco/interactive.py:375
msgid "Node: [ ID.Name(Asset amount) ]" msgid "Node: [ ID.Name(Asset amount) ]"
msgstr "节点: [ ID.名称(资产数量) ]" msgstr "节点: [ ID.名称(资产数量) ]"
#: coco/interactive.py:379 #: coco/interactive.py:377
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1" msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgstr "提示: 输入 g+节点ID 显示节点下主机. 如: g1" msgstr "提示: 输入 g+节点ID 显示节点下主机. 如: g1"
#: coco/interactive.py:387 #: coco/interactive.py:385
msgid "There is no matched node, please re-enter" msgid "There is no matched node, please re-enter"
msgstr "没有匹配分组,请重新输入" msgstr "没有匹配分组,请重新输入"
#: coco/interactive.py:417 #: coco/interactive.py:415
msgid "Select a login:: " msgid "Select a login:: "
msgstr "选择一个登录:" msgstr "选择一个登录:"
#: coco/interactive.py:440 #: coco/interactive.py:438
msgid "No system user" msgid "No system user"
msgstr "没有系统用户" msgstr "没有系统用户"
......
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