Module: deluge Branch: chunked-sessionproxy-and-gtkui-speedups Commit: 31d1a247aac094f2ce90efa50a27d80a485daad1
Author: Pedro Algarvio <[email protected]> Date: Sat May 28 16:38:14 2011 +0100 SessionProxy data restriction & Speedups. The initial data queried by the SessionProxy is restricted to the visible columns by default on the GTK UI's torrent view, which itself only queries for it's visible columns status fields, no more, no less. No need to request data that it's not going to be needed. And if at a latter statge, that data is needed it's fetched like it previously was. --- deluge/ui/gtkui/torrentview.py | 14 ++++++++++---- deluge/ui/sessionproxy.py | 34 ++++++++++++++++------------------ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 93bc8e6..ac82dbc 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -86,7 +86,7 @@ def cell_data_statusicon(column, cell, model, row, data): """Display text with an icon""" try: icon = ICON_STATE[model.get_value(row, data)] - #Supress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed + #Suppress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed with warnings.catch_warnings(): warnings.simplefilter("ignore") if cell.get_property("pixbuf") != icon: @@ -109,7 +109,7 @@ def cell_data_trackericon(column, cell, model, row, data): else: icon = create_blank_icon() - #Supress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed + #Suppress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed with warnings.catch_warnings(): warnings.simplefilter("ignore") if cell.get_property("pixbuf") != icon: @@ -202,7 +202,7 @@ class TorrentView(listview.ListView, component.Component): # We keep a copy of the previous status to compare for changes self.prev_status = {} - # Have some cached filteres statuses + # Have some cached filters statuses self.filters_cache = {} # Register the columns menu with the listview so it gets updated @@ -301,7 +301,13 @@ class TorrentView(listview.ListView, component.Component): """Start the torrentview""" # We need to get the core session state to know which torrents are in # the session so we can add them to our list. - component.get("SessionProxy").get_torrents_status({}, []).addCallback(self._on_session_state) + # Only get the status fields required for the visible columns + status_fields = [] + for listview_column in self.columns.values(): + if listview_column.column.get_visible(): + status_fields.extend(listview_column.status_field) + component.get("SessionProxy").get_torrents_status( + {}, status_fields).addCallback(self._on_session_state) def _on_session_state(self, state): self.treeview.freeze_child_notify() diff --git a/deluge/ui/sessionproxy.py b/deluge/ui/sessionproxy.py index 038586d..1731a69 100644 --- a/deluge/ui/sessionproxy.py +++ b/deluge/ui/sessionproxy.py @@ -58,7 +58,7 @@ class SessionProxy(component.Component): component.Component.__init__(self, "SessionProxy", interval=5) # Set the cache time in seconds - # This is how long data will be valid before refetching from the core + # This is how long data will be valid before re-fetching from the core self.cache_time = 1.5 # Hold the torrents' status.. {torrent_id: [time, {status_dict}], ...} @@ -81,13 +81,21 @@ class SessionProxy(component.Component): 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. + # so that upcoming queries or status updates don't throw errors. self.torrents.setdefault(torrent_id, [time.time(), {}]) self.cache_times.setdefault(torrent_id, {}) - - for chunk in self.__get_list_in_chunks(torrent_ids): - reactor.callLater(0, self.get_torrents_status, chunk, []) - + # These initial keys are the ones used for the visible columns(by + # default) on the GTK UI torrent view. If either the console-ui + # or the web-ui needs additional keys, add them here; + # There's NO need to fetch every bit of status information from + # core if it's not going to be used. Additional status fields + # will be queried later, for example, when viewing the status tab + # of a torrent. + inital_keys = [ + 'queue', 'state', 'name', 'total_wanted', 'progress', 'state', + 'download_payload_rate', 'upload_payload_rate', 'eta' + ] + self.get_torrents_status({'id': torrent_ids}, inital_keys) return client.core.get_session_state().addCallback(on_get_session_state) def stop(self): @@ -102,10 +110,6 @@ class SessionProxy(component.Component): ) self.torrents = {} - def update(self): - # Get updated full status of all torrents periodicaly - self.get_torrents_status({'id': self.torrents.keys()}, []) - def create_status_dict(self, torrent_ids, keys): """ Creates a status dict from the cache. @@ -198,6 +202,7 @@ class SessionProxy(component.Component): :rtype: dict """ + # Helper functions and callbacks --------------------------------------- def on_status(result, torrent_ids, keys): # Update the internal torrent status dict with the update values @@ -233,7 +238,7 @@ class SessionProxy(component.Component): if not filter_dict: # This means we want all the torrents status - # We get a list of any torrent_ids with expired status dicts + # We get a list of any torrent_ids with expired status dict's to_fetch = find_torrents_to_fetch(self.torrents.keys()) if to_fetch: d = client.core.get_torrents_status({"id": to_fetch}, keys, True) @@ -280,10 +285,3 @@ class SessionProxy(component.Component): def on_torrent_removed(self, torrent_id): del self.torrents[torrent_id] del self.cache_times[torrent_id] - - def __get_list_in_chunks(self, list_to_chunk, chunk_size=30): - """ - Yield successive n-sized chunks from list_to_chunk. - """ - for i in xrange(0, len(list_to_chunk), chunk_size): - yield list_to_chunk[i:i+chunk_size] -- You received this message because you are subscribed to the Google Groups "deluge-commit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/deluge-commit?hl=en.
