Changeset 12747


Ignore:
Timestamp:
Aug 26, 2011, 12:43:35 AM (12 years ago)
Author:
jordan
Message:

(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.

Location:
trunk/web/javascript
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/javascript/torrent-row.js

    r12736 r12747  
    370370                return this._torrent;
    371371        },
     372        getTorrentId: function() {
     373                return this.getTorrent().getId();
     374        },
    372375        isEven: function() {
    373376                return this.getElement().className.indexOf('even') != -1;
  • trunk/web/javascript/transmission.js

    r12745 r12747  
    410410                for (var i=0, row; row=this._rows[i]; ++i)
    411411                        if (row.isSelected())
    412                                 s.push(row.getTorrent().getId());
     412                                s.push(row.getTorrentId());
    413413                return s;
    414414        },
     
    445445        indexOfLastTorrent: function() {
    446446                for (var i=0, r; r=this._rows[i]; ++i)
    447                         if (r.getTorrent().getId() === this._last_torrent_clicked)
     447                        if (r.getTorrentId() === this._last_torrent_clicked)
    448448                                return i;
    449449                return -1;
     
    544544                                        this.setSelectedRow(r);
    545545                        }
    546                         this._last_torrent_clicked = r.getTorrent().getId();
     546                        this._last_torrent_clicked = r.getTorrentId();
    547547                        this.scrollToRow(r);
    548548                }
     
    16361636                }
    16371637
    1638                 this._last_torrent_clicked = row.getTorrent().getId();
     1638                this._last_torrent_clicked = row.getTorrentId();
    16391639        },
    16401640
     
    19791979        },
    19801980
     1981        matchesTorrentList: function(torrents)
     1982        {
     1983                if (!torrents || !this._rows)
     1984                        return false;
     1985                if (torrents.length !== this._rows.length)
     1986                        return false;
     1987
     1988                for (var i=0, tor; tor=torrents[i]; ++i)
     1989                        if (tor.getId() !== this._rows[i].getTorrentId())
     1990                                return false;
     1991
     1992                return true;
     1993        },
     1994
    19811995        refilter: function()
    19821996        {
     
    19841998                delete this.refilterTimer;
    19851999
    1986                 // decide which torrents to show
     2000                // make a filtered, sorted array of our torrents
    19872001                var keep = [];
    19882002                var all_torrents = this.getAllTorrents();
     
    19902004                        if (t.test(this[Prefs._FilterMode], this._current_search, this.filterTracker))
    19912005                                keep.push(t);
    1992 
    1993                 // sort the torrents we're going to show
    1994                 Torrent.sortTorrents(keep, this[Prefs._SortMethod],
    1995                                            this[Prefs._SortDirection]);
    1996 
    1997                 // make a temporary backup of the selection
    1998                 var sel = this.getSelectedTorrents();
    1999                 var new_sel_count = 0;
    2000 
    2001                 // make the new rows
    2002                 var tr = this;
    2003                 var rows = [ ];
    2004                 var fragment = document.createDocumentFragment();
    2005                 for (var i=0, tor; tor=keep[i]; ++i)
     2006                Torrent.sortTorrents(keep, this[Prefs._SortMethod], this[Prefs._SortDirection]);
     2007
     2008                // maybe rebuild the rows
     2009                if (!this.matchesTorrentList(keep))
    20062010                {
    2007                         var is_selected = sel.indexOf(tor) !== -1;
    2008                         var row = new TorrentRow(this.torrentRenderer, this, tor, is_selected);
    2009                         row.setEven((i+1) % 2 == 0);
    2010                         if (is_selected)
    2011                                 new_sel_count++;
    2012                         if (!iPhone) {
    2013                                 var b = row.getToggleRunningButton();
    2014                                 if (b)
    2015                                         $(b).click({r:row}, function(ev) {tr.onToggleRunningClicked(ev);});
     2011                        var old_sel = this.getSelectedTorrents();
     2012                        var new_sel_count = 0;
     2013
     2014                        // make the new rows
     2015                        var tr = this;
     2016                        var rows = [ ];
     2017                        var fragment = document.createDocumentFragment();
     2018                        for (var i=0, tor; tor=keep[i]; ++i)
     2019                        {
     2020                                var is_selected = old_sel.indexOf(tor) !== -1;
     2021                                var row = new TorrentRow(this.torrentRenderer, this, tor, is_selected);
     2022                                row.setEven((i+1) % 2 == 0);
     2023                                if (is_selected)
     2024                                        new_sel_count++;
     2025                                if (!iPhone) {
     2026                                        var b = row.getToggleRunningButton();
     2027                                        if (b)
     2028                                                $(b).click({r:row}, function(ev) {tr.onToggleRunningClicked(ev);});
     2029                                }
     2030                                $(row.getElement()).click({r: row}, function(ev) {tr.onRowClicked(ev,ev.data.r);});
     2031                                $(row.getElement()).dblclick(function() { tr.toggleInspector();});
     2032                                fragment.appendChild(row.getElement());
     2033                                rows.push(row);
    20162034                        }
    2017                         $(row.getElement()).click({r: row}, function(ev) {tr.onRowClicked(ev,ev.data.r);});
    2018                         $(row.getElement()).dblclick(function() { tr.toggleInspector();});
    2019                         fragment.appendChild(row.getElement());
    2020                         rows.push(row);
    2021                 }
    2022                 $('ul.torrent_list').empty();
    2023                 delete this._rows;
    2024                 this._rows = rows;
    2025                 this._torrent_list.appendChild(fragment);
     2035                        $('ul.torrent_list').empty();
     2036                        delete this._rows;
     2037                        this._rows = rows;
     2038                        this._torrent_list.appendChild(fragment);
     2039
     2040                        if (old_sel.length !== new_sel_count)
     2041                                this.selectionChanged();
     2042                }
    20262043
    20272044                // sync gui
    20282045                this.updateStatusbar();
    2029                 if (sel.length !== new_sel_count)
    2030                         this.selectionChanged();
    20312046                this.refreshFilterButton();
    20322047        },
Note: See TracChangeset for help on using the changeset viewer.