Attempt to reduce the number of updates to the TorrentView by caching
the previous status batch dictionary and only updating the difference.
This commit is contained in:
parent
44c82db9a8
commit
dd395b8c9c
|
@ -121,6 +121,7 @@ class TorrentView(listview.ListView, component.Component):
|
||||||
self.load_state("torrentview.state")
|
self.load_state("torrentview.state")
|
||||||
|
|
||||||
self.status_signal_received = True
|
self.status_signal_received = True
|
||||||
|
self.previous_batched_status = {}
|
||||||
|
|
||||||
# Register the columns menu with the listview so it gets updated
|
# Register the columns menu with the listview so it gets updated
|
||||||
# accordingly.
|
# accordingly.
|
||||||
|
@ -294,21 +295,44 @@ class TorrentView(listview.ListView, component.Component):
|
||||||
"""Callback function for get_torrents_status(). 'status' should be a
|
"""Callback function for get_torrents_status(). 'status' should be a
|
||||||
dictionary of {torrent_id: {key, value}}."""
|
dictionary of {torrent_id: {key, value}}."""
|
||||||
status = pickle.loads(status)
|
status = pickle.loads(status)
|
||||||
|
# Extract differences in this batch against the previous one.
|
||||||
|
# This is to prevent updating stuff we don't need to and should save
|
||||||
|
# GTK from redrawing needlessly.
|
||||||
|
new_status = {}
|
||||||
|
for torrent_id in status.keys():
|
||||||
|
if torrent_id in self.previous_batched_status.keys():
|
||||||
|
old = self.previous_batched_status[torrent_id]
|
||||||
|
new = status[torrent_id]
|
||||||
|
diff = {}
|
||||||
|
for key in new.keys():
|
||||||
|
# There is a difference, so lets add it to our new dict
|
||||||
|
if new[key] != old[key]:
|
||||||
|
diff[key] = new[key]
|
||||||
|
if len(diff.keys()) > 0:
|
||||||
|
new_status[torrent_id] = diff
|
||||||
|
else:
|
||||||
|
# The torrent_id is not in the previous status
|
||||||
|
new_status[torrent_id] = status[torrent_id]
|
||||||
|
|
||||||
|
self.previous_batched_status = status
|
||||||
|
|
||||||
row = self.liststore.get_iter_first()
|
row = self.liststore.get_iter_first()
|
||||||
while row != None:
|
while row != None:
|
||||||
torrent_id = self.liststore.get_value(
|
torrent_id = self.liststore.get_value(
|
||||||
row, self.columns["torrent_id"].column_indices[0])
|
row, self.columns["torrent_id"].column_indices[0])
|
||||||
if torrent_id in status.keys():
|
if torrent_id in new_status.keys():
|
||||||
# Set values for each column in the row
|
# Set values for each column in the row
|
||||||
for column in self.columns_to_update:
|
for column in self.columns_to_update:
|
||||||
column_index = self.get_column_index(column)
|
column_index = self.get_column_index(column)
|
||||||
if type(column_index) is not list:
|
if type(column_index) is not list:
|
||||||
# We only have a single list store column we need to
|
# We only have a single list store column we need to
|
||||||
# update
|
# update
|
||||||
|
if self.columns[column].status_field[0] in \
|
||||||
|
new_status[torrent_id]:
|
||||||
try:
|
try:
|
||||||
self.liststore.set_value(row,
|
self.liststore.set_value(row,
|
||||||
column_index,
|
column_index,
|
||||||
status[torrent_id][
|
new_status[torrent_id][
|
||||||
self.columns[column].status_field[0]])
|
self.columns[column].status_field[0]])
|
||||||
except (TypeError, KeyError), e:
|
except (TypeError, KeyError), e:
|
||||||
log.warning("Unable to update column %s: %s",
|
log.warning("Unable to update column %s: %s",
|
||||||
|
@ -317,10 +341,13 @@ class TorrentView(listview.ListView, component.Component):
|
||||||
# We have more than 1 liststore column to update
|
# We have more than 1 liststore column to update
|
||||||
for index in column_index:
|
for index in column_index:
|
||||||
# Only update the column if the status field exists
|
# Only update the column if the status field exists
|
||||||
|
if self.columns[column].status_field[
|
||||||
|
column_index.index(index)] in \
|
||||||
|
new_status[torrent_id]:
|
||||||
try:
|
try:
|
||||||
self.liststore.set_value(row,
|
self.liststore.set_value(row,
|
||||||
index,
|
index,
|
||||||
status[torrent_id][
|
new_status[torrent_id][
|
||||||
self.columns[column].status_field[
|
self.columns[column].status_field[
|
||||||
column_index.index(index)]])
|
column_index.index(index)]])
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Reference in New Issue