From 22c07f8e10986d9394cd4ba1146793b26dc4de76 Mon Sep 17 00:00:00 2001 From: Martijn Voncken Date: Tue, 22 Jan 2008 18:19:30 +0000 Subject: [PATCH] use async api for torrent_list(index-page) --- deluge/ui/webui/webui_plugin/pages.py | 4 ++-- .../webui_plugin/tests/multicall_notepad.py | 9 +++++--- deluge/ui/webui/webui_plugin/utils.py | 21 ++++++++++++++++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/deluge/ui/webui/webui_plugin/pages.py b/deluge/ui/webui/webui_plugin/pages.py index 79474248b..92b2f9ba2 100644 --- a/deluge/ui/webui/webui_plugin/pages.py +++ b/deluge/ui/webui/webui_plugin/pages.py @@ -113,8 +113,8 @@ class index: @deco.auto_refreshed def GET(self, name): vars = web.input(sort=None, order=None ,filter=None , category=None) - torrent_list = [get_torrent_status(torrent_id) - for torrent_id in ws.proxy.get_session_state()] + + torrent_list = get_torrent_list() all_torrents = torrent_list[:] #filter-state diff --git a/deluge/ui/webui/webui_plugin/tests/multicall_notepad.py b/deluge/ui/webui/webui_plugin/tests/multicall_notepad.py index f6682eb5c..501f48c45 100644 --- a/deluge/ui/webui/webui_plugin/tests/multicall_notepad.py +++ b/deluge/ui/webui/webui_plugin/tests/multicall_notepad.py @@ -66,13 +66,16 @@ print torrent_list start = time.time() torrent_ids = ws.proxy.get_session_state() #Syc-api. -torrent_list = [] +torrent_dict = {} for id in torrent_ids: - async_proxy.get_torrent_status(torrent_list.append, id, []) + async_proxy.get_torrent_status(dict_cb(id,torrent_dict), id, []) async_proxy.force_call(block=True) print "Async-list:",time.time() - start -print torrent_list +print torrent_dict + + +print sorted(torrent_list[0].keys()) diff --git a/deluge/ui/webui/webui_plugin/utils.py b/deluge/ui/webui/webui_plugin/utils.py index b20cfad7a..e84e0d2ab 100644 --- a/deluge/ui/webui/webui_plugin/utils.py +++ b/deluge/ui/webui/webui_plugin/utils.py @@ -150,6 +150,7 @@ def enhance_torrent_status(torrent_id,status): in: raw torrent_status out: enhanced torrent_staus """ + status = Storage(status) #add missing values for deluge 0.6: for key in TORRENT_KEYS: if not key in status: @@ -221,11 +222,29 @@ def get_torrent_status(torrent_id): helper method. enhance ws.proxy.get_torrent_status with some extra data """ - status = Storage(ws.proxy.get_torrent_status(torrent_id,TORRENT_KEYS)) + status = ws.proxy.get_torrent_status(torrent_id,TORRENT_KEYS) return enhance_torrent_status(torrent_id, status) + +def get_torrent_list(): + """ + uses async. + """ + torrent_ids = ws.proxy.get_session_state() #Syc-api. + torrent_dict = {} + for id in torrent_ids: + ws.async_proxy.get_torrent_status(dict_cb(id,torrent_dict), id, []) + ws.async_proxy.force_call(block=True) + + return [enhance_torrent_status(id, status) + for id, status in torrent_dict.iteritems()] + + + + + def get_categories(torrent_list): trackers = [(torrent['category'] or 'unknown') for torrent in torrent_list] categories = {}