mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-05 08:03:40 +00:00
Speed optimizations for the torrentview
This commit is contained in:
parent
aa969fd830
commit
762ad783e2
@ -313,18 +313,12 @@ class TorrentView(listview.ListView, component.Component):
|
|||||||
component.get("SessionProxy").get_torrents_status({}, []).addCallback(self._on_session_state)
|
component.get("SessionProxy").get_torrents_status({}, []).addCallback(self._on_session_state)
|
||||||
|
|
||||||
def _on_session_state(self, state):
|
def _on_session_state(self, state):
|
||||||
self.treeview.freeze_child_notify()
|
self.add_rows(state)
|
||||||
model = self.treeview.get_model()
|
|
||||||
for torrent_id in state:
|
|
||||||
self.add_row(torrent_id, update=False)
|
|
||||||
self.mark_dirty(torrent_id)
|
|
||||||
self.treeview.set_model(model)
|
|
||||||
self.treeview.thaw_child_notify()
|
|
||||||
self.got_state = True
|
self.got_state = True
|
||||||
# Update the view right away with our status
|
# Update the view right away with our status
|
||||||
self.status = state
|
self.status = state
|
||||||
self.set_columns_to_update()
|
self.set_columns_to_update()
|
||||||
self.update_view()
|
self.update_view(first_run=True)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""Stops the torrentview"""
|
"""Stops the torrentview"""
|
||||||
@ -399,40 +393,77 @@ class TorrentView(listview.ListView, component.Component):
|
|||||||
# Send a status request
|
# Send a status request
|
||||||
gobject.idle_add(self.send_status_request)
|
gobject.idle_add(self.send_status_request)
|
||||||
|
|
||||||
def update_view(self, columns=None):
|
|
||||||
"""Update the view. If columns is not None, it will attempt to only
|
def update_view(self, first_run=False):
|
||||||
update those columns selected.
|
"""Update the view."""
|
||||||
"""
|
|
||||||
filter_column = self.columns["filter"].column_indices[0]
|
filter_column = self.columns["filter"].column_indices[0]
|
||||||
# Update the torrent view model with data we've received
|
|
||||||
status = self.status
|
status = self.status
|
||||||
|
sort_settings = (None, None)
|
||||||
|
model = self.treeview.get_model()
|
||||||
|
|
||||||
|
self.treeview.freeze_child_notify()
|
||||||
|
|
||||||
|
if first_run:
|
||||||
|
# Disable sort if it's the first run.
|
||||||
|
sort_settings = model.get_sort_column_id()
|
||||||
|
model.set_sort_column_id(-1, gtk.SORT_ASCENDING)
|
||||||
|
|
||||||
|
# Create a list of tuples with the index of the column, and the column name
|
||||||
|
fields_to_update = []
|
||||||
|
for column in self.columns_to_update:
|
||||||
|
column_index = self.get_column_index(column)
|
||||||
|
for i, status_field in enumerate(self.columns[column].status_field):
|
||||||
|
fields_to_update.append((column_index[i], status_field))
|
||||||
|
|
||||||
for row in self.liststore:
|
for row in self.liststore:
|
||||||
torrent_id = row[self.columns["torrent_id"].column_indices[0]]
|
torrent_id = row[self.columns["torrent_id"].column_indices[0]]
|
||||||
|
# Do not test if the torrent_id is in status. Instead
|
||||||
if not torrent_id in status.keys():
|
# we expect the torrent_id to be in status and prev_status,
|
||||||
row[filter_column] = False
|
# as it will be as long as the list isn't changed by the user
|
||||||
else:
|
torrent_id_in_status = False
|
||||||
row[filter_column] = True
|
try:
|
||||||
if torrent_id in self.prev_status and status[torrent_id] == self.prev_status[torrent_id]:
|
torrent_status = status[torrent_id]
|
||||||
# The status dict is the same, so do not update
|
torrent_id_in_status = True
|
||||||
|
if torrent_status == self.prev_status[torrent_id]:
|
||||||
|
if row[filter_column] is False:
|
||||||
|
row[filter_column] = True
|
||||||
|
# The status dict is the same, so do not update this torrent
|
||||||
continue
|
continue
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Set values for each column in the row
|
if not torrent_id_in_status:
|
||||||
for column in self.columns_to_update:
|
if row[filter_column] is True:
|
||||||
column_index = self.get_column_index(column)
|
row[filter_column] = False
|
||||||
for i, status_field in enumerate(self.columns[column].status_field):
|
else:
|
||||||
if status_field in status[torrent_id]:
|
if row[filter_column] is False:
|
||||||
try:
|
row[filter_column] = True
|
||||||
# Only update if different
|
to_update = []
|
||||||
row_value = status[torrent_id][status_field]
|
# Add all the values that have changed to the list
|
||||||
if row[column_index[i]] != row_value:
|
for i, status_field in fields_to_update:
|
||||||
row[column_index[i]] = row_value
|
try:
|
||||||
except Exception, e:
|
if not status[torrent_id].has_key(status_field):
|
||||||
log.debug("%s", e)
|
continue
|
||||||
|
row_value = status[torrent_id][status_field]
|
||||||
|
if row[i] != row_value:
|
||||||
|
to_update.append(i)
|
||||||
|
to_update.append(row_value)
|
||||||
|
except KeyError, e:
|
||||||
|
# if status_field in status[torrent_id] -> False
|
||||||
|
field_value_key_error_count += 1
|
||||||
|
pass
|
||||||
|
except Exception, e:
|
||||||
|
log.debug("%s", e)
|
||||||
|
# Update all the changed values of the row
|
||||||
|
if to_update:
|
||||||
|
self.liststore.set(row.iter, *to_update)
|
||||||
|
|
||||||
|
if sort_settings[0] is not None:
|
||||||
|
# Reenable sorting
|
||||||
|
model.set_sort_column_id(*sort_settings)
|
||||||
|
|
||||||
|
self.treeview.thaw_child_notify()
|
||||||
component.get("MenuBar").update_menu()
|
component.get("MenuBar").update_menu()
|
||||||
|
|
||||||
self.prev_status = status
|
self.prev_status = status
|
||||||
|
|
||||||
def _on_get_torrents_status(self, status):
|
def _on_get_torrents_status(self, status):
|
||||||
@ -462,6 +493,15 @@ class TorrentView(listview.ListView, component.Component):
|
|||||||
if update:
|
if update:
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
def add_rows(self, state):
|
||||||
|
"""Adds all the torrents from state to self.liststore"""
|
||||||
|
torrent_id_column = self.columns["torrent_id"].column_indices[0]
|
||||||
|
dirty_column = self.columns["dirty"].column_indices[0]
|
||||||
|
for i, torrent_id in enumerate(state):
|
||||||
|
# Insert a new row to the liststore
|
||||||
|
row = self.liststore.append()
|
||||||
|
self.liststore.set(row, torrent_id_column, torrent_id, dirty_column, True)
|
||||||
|
|
||||||
def remove_row(self, torrent_id):
|
def remove_row(self, torrent_id):
|
||||||
"""Removes a row with torrent_id"""
|
"""Removes a row with torrent_id"""
|
||||||
for row in self.liststore:
|
for row in self.liststore:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user