use async api for torrent_list(index-page)

This commit is contained in:
Martijn Voncken 2008-01-22 18:19:30 +00:00
parent 9236e9bff2
commit 22c07f8e10
3 changed files with 28 additions and 6 deletions

View File

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

View File

@ -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())

View File

@ -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 = {}