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,37 +295,63 @@ 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
|
||||||
try:
|
if self.columns[column].status_field[0] in \
|
||||||
self.liststore.set_value(row,
|
new_status[torrent_id]:
|
||||||
column_index,
|
try:
|
||||||
status[torrent_id][
|
self.liststore.set_value(row,
|
||||||
self.columns[column].status_field[0]])
|
column_index,
|
||||||
except (TypeError, KeyError), e:
|
new_status[torrent_id][
|
||||||
log.warning("Unable to update column %s: %s",
|
self.columns[column].status_field[0]])
|
||||||
column, e)
|
except (TypeError, KeyError), e:
|
||||||
|
log.warning("Unable to update column %s: %s",
|
||||||
|
column, e)
|
||||||
else:
|
else:
|
||||||
# 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
|
||||||
try:
|
if self.columns[column].status_field[
|
||||||
self.liststore.set_value(row,
|
column_index.index(index)] in \
|
||||||
index,
|
new_status[torrent_id]:
|
||||||
status[torrent_id][
|
try:
|
||||||
self.columns[column].status_field[
|
self.liststore.set_value(row,
|
||||||
column_index.index(index)]])
|
index,
|
||||||
except:
|
new_status[torrent_id][
|
||||||
pass
|
self.columns[column].status_field[
|
||||||
|
column_index.index(index)]])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
row = self.liststore.iter_next(row)
|
row = self.liststore.iter_next(row)
|
||||||
self.status_signal_received = True
|
self.status_signal_received = True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue