1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-11 14:43:42 +00:00

(trunk web) in Transmission.refilter(), don't rebuild the row array if the filtered + sorted list of torrents hasn't changed. This is a big CPU win on large torrent lists.

This commit is contained in:
Jordan Lee 2011-08-26 00:43:35 +00:00
parent ab7305fe64
commit e1641792e9
2 changed files with 55 additions and 37 deletions

View file

@ -369,6 +369,9 @@ TorrentRow.prototype =
getTorrent: function() {
return this._torrent;
},
getTorrentId: function() {
return this.getTorrent().getId();
},
isEven: function() {
return this.getElement().className.indexOf('even') != -1;
},

View file

@ -409,7 +409,7 @@ Transmission.prototype =
var s = [];
for (var i=0, row; row=this._rows[i]; ++i)
if (row.isSelected())
s.push(row.getTorrent().getId());
s.push(row.getTorrentId());
return s;
},
@ -444,7 +444,7 @@ Transmission.prototype =
indexOfLastTorrent: function() {
for (var i=0, r; r=this._rows[i]; ++i)
if (r.getTorrent().getId() === this._last_torrent_clicked)
if (r.getTorrentId() === this._last_torrent_clicked)
return i;
return -1;
},
@ -543,7 +543,7 @@ Transmission.prototype =
else
this.setSelectedRow(r);
}
this._last_torrent_clicked = r.getTorrent().getId();
this._last_torrent_clicked = r.getTorrentId();
this.scrollToRow(r);
}
else if (shift)
@ -1635,7 +1635,7 @@ Transmission.prototype =
this.setSelectedRow(row);
}
this._last_torrent_clicked = row.getTorrent().getId();
this._last_torrent_clicked = row.getTorrentId();
},
deleteTorrents: function(torrent_ids)
@ -1978,24 +1978,37 @@ Transmission.prototype =
}
},
matchesTorrentList: function(torrents)
{
if (!torrents || !this._rows)
return false;
if (torrents.length !== this._rows.length)
return false;
for (var i=0, tor; tor=torrents[i]; ++i)
if (tor.getId() !== this._rows[i].getTorrentId())
return false;
return true;
},
refilter: function()
{
clearTimeout(this.refilterTimer);
delete this.refilterTimer;
// decide which torrents to show
// make a filtered, sorted array of our torrents
var keep = [];
var all_torrents = this.getAllTorrents();
for (var i=0, t; t=all_torrents[i]; ++i)
if (t.test(this[Prefs._FilterMode], this._current_search, this.filterTracker))
keep.push(t);
Torrent.sortTorrents(keep, this[Prefs._SortMethod], this[Prefs._SortDirection]);
// sort the torrents we're going to show
Torrent.sortTorrents(keep, this[Prefs._SortMethod],
this[Prefs._SortDirection]);
// make a temporary backup of the selection
var sel = this.getSelectedTorrents();
// maybe rebuild the rows
if (!this.matchesTorrentList(keep))
{
var old_sel = this.getSelectedTorrents();
var new_sel_count = 0;
// make the new rows
@ -2004,7 +2017,7 @@ Transmission.prototype =
var fragment = document.createDocumentFragment();
for (var i=0, tor; tor=keep[i]; ++i)
{
var is_selected = sel.indexOf(tor) !== -1;
var is_selected = old_sel.indexOf(tor) !== -1;
var row = new TorrentRow(this.torrentRenderer, this, tor, is_selected);
row.setEven((i+1) % 2 == 0);
if (is_selected)
@ -2024,10 +2037,12 @@ Transmission.prototype =
this._rows = rows;
this._torrent_list.appendChild(fragment);
if (old_sel.length !== new_sel_count)
this.selectionChanged();
}
// sync gui
this.updateStatusbar();
if (sel.length !== new_sel_count)
this.selectionChanged();
this.refreshFilterButton();
},