Module: deluge
Branch: chunked-sessionproxy-and-gtkui-speedups
Commit: f360ad88fb1de3730bdf7c39622f3ed931c28121

Author: Pedro Algarvio <pe...@algarvio.me>
Date:   Tue May 17 02:34:47 2011 +0100

Bugfixes for chunked session proxy and visible torrents.

If there are no visible torrent, do try to get any info from core and don't 
fail trying it.
On the session proxy, when querying for a single torrent's status, the data we 
get back is not similar to that of when querying for multiple. Handle both.

---

 deluge/ui/gtkui/torrentview.py |    6 ++++--
 deluge/ui/sessionproxy.py      |   28 +++++++++++++++++-----------
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py
index 8a4db16..6112c50 100644
--- a/deluge/ui/gtkui/torrentview.py
+++ b/deluge/ui/gtkui/torrentview.py
@@ -540,13 +540,15 @@ class TorrentView(listview.ListView, component.Component):
 
     def get_visible_torrents(self, only_seen_in_treeview=False):
         if only_seen_in_treeview:
-            first_seen, last_seen = self.treeview.get_visible_range()
+            visible_range = self.treeview.get_visible_range()
+            if not visible_range:
+                return []
+            first_seen, last_seen = visible_range
             model = self.treeview.get_model()
             return [
                 model[n][self.get_column_index('torrent_id')[0]] for n in
                 range(first_seen[0], last_seen[0]+1)
             ]
-
         return self.status.keys()
 
     ### Callbacks ###
diff --git a/deluge/ui/sessionproxy.py b/deluge/ui/sessionproxy.py
index 34ea5fe..29ce7b3 100644
--- a/deluge/ui/sessionproxy.py
+++ b/deluge/ui/sessionproxy.py
@@ -34,7 +34,7 @@
 #
 
 import logging
-from twisted.internet.defer import maybeDeferred, succeed
+from twisted.internet.defer import inlineCallbacks, maybeDeferred, succeed, 
returnValue
 
 import deluge.component as component
 from deluge.ui.client import client
@@ -78,16 +78,20 @@ class SessionProxy(component.Component):
         )
 
     def start(self):
+        @inlineCallbacks
         def on_get_session_state(torrent_ids):
+            for torrent_id in torrent_ids:
+                # Let's at least store the torrent ids with empty statuses
+                # so that upcomming queries don't throw errors.
+                self.__on_torrents_status({torrent_id: {}})
+
+            # Query for complete status in chunks
             for torrent_ids_chunk in self.__get_list_in_chunks(torrent_ids):
-                torrent_ids_chunk = list(torrent_ids_chunk)
-                print 'querying status for chunk', torrent_ids_chunk
-                d = client.core.get_torrents_status(
+                chunk_status = yield client.core.get_torrents_status(
                     {'id': torrent_ids_chunk}, [], True
-                ).addCallback(self.__on_torrents_status)
-            return d.addCallback(
-                self.create_status_dict_from_deferred, torrent_ids, []
-            )
+                )
+                self.__on_torrents_status(chunk_status)
+            returnValue(None)
         return 
client.core.get_session_state().addCallback(on_get_session_state)
 
     def stop(self):
@@ -163,7 +167,7 @@ class SessionProxy(component.Component):
             else:
                 d = client.core.get_torrent_status(
                     torrent_id, keys_to_get, True
-                ).addCallback(self.__on_torrents_status)
+                ).addCallback(self.__on_torrents_status, torrent_id)
                 return d.addCallback(
                     self.create_status_dict_from_deferred,
                     [torrent_id],
@@ -172,7 +176,7 @@ class SessionProxy(component.Component):
         else:
             d = client.core.get_torrent_status(
                 torrent_id, keys, True
-            ).addCallback(self.__on_torrents_status)
+            ).addCallback(self.__on_torrents_status, torrent_id)
             return d.addCallback(
                 self.create_status_dict_from_deferred,
                 None,
@@ -282,8 +286,10 @@ class SessionProxy(component.Component):
         del self.torrents[torrent_id]
         del self.cache_times[torrent_id]
 
-    def __on_torrents_status(self, status):
+    def __on_torrents_status(self, status, torrent_id=None):
         t = time.time()
+        if torrent_id:
+            status = {torrent_id: status}
         for key, value in status.items():
             self.torrents.setdefault(key, [t, value])
             self.torrents[key][0] = t

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to deluge-commit@googlegroups.com.
To unsubscribe from this group, send email to 
deluge-commit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to