mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 12:28:52 +00:00
(trunk web) speed improvments
This commit is contained in:
@@ -24,6 +24,20 @@ Torrent.prototype =
|
||||
* Constructor
|
||||
*/
|
||||
initialize: function(controller, data) {
|
||||
this._id = data.id;
|
||||
this._is_private = data.isPrivate;
|
||||
this._hashString = data.hashString;
|
||||
this._date = data.addedDate;
|
||||
this._size = data.totalSize;
|
||||
this._tracker = data.announceURL;
|
||||
this._comment = data.comment;
|
||||
this._creator = data.creator;
|
||||
this._creator_date = data.dateCreated;
|
||||
this._sizeWhenDone = data.sizeWhenDone;
|
||||
this._name = data.name;
|
||||
this._name_lc = this._name.toLowerCase( );
|
||||
|
||||
|
||||
// Create a new <li> element
|
||||
var element = $('<li/>');
|
||||
element.addClass('torrent');
|
||||
@@ -88,30 +102,32 @@ Torrent.prototype =
|
||||
|
||||
// insert the element
|
||||
$('#torrent_list').append(this._element);
|
||||
this.initializeTorrentFilesInspectorGroup(data.files.length);
|
||||
|
||||
for (var i = 0; i < data.files.length; i++) {
|
||||
var file = data.files[i];
|
||||
file.index = i;
|
||||
file.torrent = this;
|
||||
file.priority = data.priorities[i];
|
||||
file.wanted = data.wanted[i];
|
||||
var torrentFile = new TorrentFile(file);
|
||||
this._files.push(torrentFile);
|
||||
this._fileList.append(
|
||||
torrentFile.element().addClass(i % 2 ? 'even' : 'odd').addClass('inspector_torrent_file_list_entry')
|
||||
);
|
||||
|
||||
this._files = [];
|
||||
this.initializeTorrentFilesInspectorGroup();
|
||||
if(data.files){
|
||||
if(data.files.length == 1)
|
||||
this._fileList.addClass('single_file');
|
||||
for (var i = 0; i < data.files.length; i++) {
|
||||
var file = data.files[i];
|
||||
file.index = i;
|
||||
file.torrent = this;
|
||||
file.priority = data.fileStats[i].priority;
|
||||
file.wanted = data.fileStats[i].wanted;
|
||||
var torrentFile = new TorrentFile(file);
|
||||
this._files.push(torrentFile);
|
||||
this._fileList.append(
|
||||
torrentFile.element().addClass(i % 2 ? 'even' : 'odd').addClass('inspector_torrent_file_list_entry')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update all the labels etc
|
||||
this.refresh(data);
|
||||
},
|
||||
|
||||
initializeTorrentFilesInspectorGroup: function(length) {
|
||||
this._files = [];
|
||||
this._fileList = $('<ul/>').addClass('inspector_torrent_file_list').addClass('inspector_group').hide();
|
||||
if(length == 1)
|
||||
this._fileList.addClass('single_file');
|
||||
$('#inspector_file_list').append(this._fileList);
|
||||
},
|
||||
|
||||
@@ -278,24 +294,6 @@ Torrent.prototype =
|
||||
* Refresh display
|
||||
*/
|
||||
refreshData: function(data) {
|
||||
// These variables never change after the inital load
|
||||
if (data.isPrivate) this._is_private = data.isPrivate;
|
||||
if (data.hashString) this._hashString = data.hashString;
|
||||
if (data.addedDate) this._date = data.addedDate;
|
||||
if (data.totalSize) this._size = data.totalSize;
|
||||
if (data.announceURL) this._tracker = data.announceURL;
|
||||
if (data.comment) this._comment = data.comment;
|
||||
if (data.creator) this._creator = data.creator;
|
||||
if (data.dateCreated) this._creator_date = data.dateCreated;
|
||||
if (data.sizeWhenDone) this._sizeWhenDone = data.sizeWhenDone;
|
||||
if (data.path) this._torrent_file = data.path;//FIXME
|
||||
if (data.name) {
|
||||
this._name = data.name;
|
||||
this._name_lc = this._name.toLowerCase( );
|
||||
}
|
||||
|
||||
// Set the regularly-changing torrent variables
|
||||
this._id = data.id;
|
||||
this._completed = data.haveUnchecked + data.haveValid;
|
||||
this._verified = data.haveValid;
|
||||
this._leftUntilDone = data.leftUntilDone;
|
||||
@@ -314,16 +312,28 @@ Torrent.prototype =
|
||||
this._total_seeders = Math.max( 0, data.seeders );
|
||||
this._state = data.status;
|
||||
|
||||
if (data.files) {
|
||||
for (var i = 0; i < data.files.length; i++) {
|
||||
var file_data = data.files[i];
|
||||
if (data.priorities) { file_data.priority = data.priorities[i]; }
|
||||
if (data.wanted) { file_data.wanted = data.wanted[i]; }
|
||||
if (data.fileStats) {
|
||||
for (var i = 0; i < data.fileStats.length; i++) {
|
||||
var file_data = {};
|
||||
file_data.priority = data.fileStats[i].priority;
|
||||
file_data.wanted = data.fileStats[i].wanted;
|
||||
file_data.bytesCompleted = data.fileStats[i].bytesCompleted;
|
||||
this._files[i].readAttributes(file_data);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
refreshFileData: function(data) {
|
||||
for (var i = 0; i < data.fileStats.length; i++) {
|
||||
var file_data = {};
|
||||
file_data.priority = data.fileStats[i].priority;
|
||||
file_data.wanted = data.fileStats[i].wanted;
|
||||
file_data.bytesCompleted = data.fileStats[i].bytesCompleted;
|
||||
this._files[i].readAttributes(file_data);
|
||||
this._files[i].refreshHTML();
|
||||
}
|
||||
},
|
||||
|
||||
refreshHTML: function() {
|
||||
var progress_details;
|
||||
var peer_details;
|
||||
|
||||
@@ -44,7 +44,8 @@ Transmission.prototype =
|
||||
this.preloadImages();
|
||||
|
||||
// Set up user events
|
||||
$('#pause_all_link').bind('click', this.stopAllClicked );
|
||||
var tr = this;
|
||||
$('#pause_all_link').bind('click', function(){ tr.stopAllClicked(); });
|
||||
$('#resume_all_link').bind('click', this.startAllClicked);
|
||||
$('#pause_selected_link').bind('click', this.stopSelectedClicked );
|
||||
$('#resume_selected_link').bind('click', this.startSelectedClicked);
|
||||
@@ -64,7 +65,7 @@ Transmission.prototype =
|
||||
$('#preferences_link').bind('click', this.releaseClutchPreferencesButton);
|
||||
} else {
|
||||
$(document).bind('keydown', this.keyDown);
|
||||
$('#torrent_container').bind('click', this.deselectAll);
|
||||
$('#torrent_container').bind('click', function(){ tr.deselectAll( true ); });
|
||||
$('#open_link').bind('click', this.openTorrentClicked);
|
||||
$('#filter_toggle_link').bind('click', this.toggleFilterClicked);
|
||||
$('#inspector_link').bind('click', this.toggleInspectorClicked);
|
||||
@@ -83,8 +84,10 @@ Transmission.prototype =
|
||||
this.initializeSettings( );
|
||||
|
||||
// Get preferences & torrents from the daemon
|
||||
var tr = this;
|
||||
this.remote.loadDaemonPrefs( );
|
||||
this.remote.loadTorrents( true );
|
||||
this.initalizeAllTorrents();
|
||||
|
||||
this.togglePeriodicRefresh( true );
|
||||
},
|
||||
|
||||
@@ -656,26 +659,19 @@ Transmission.prototype =
|
||||
* Turn the periodic ajax-refresh on & off
|
||||
*/
|
||||
togglePeriodicRefresh: function(state) {
|
||||
var tr = this;
|
||||
if (state && this._periodic_refresh == null) {
|
||||
// sanity check
|
||||
if( !this[Prefs._RefreshRate] )
|
||||
this[Prefs._RefreshRate] = 5;
|
||||
remote = this.remote;
|
||||
this._periodic_refresh = setInterval(this.periodicRefresh, this[Prefs._RefreshRate] * 1000 );
|
||||
this._periodic_refresh = setInterval(function(){ tr.refreshTorrents(); }, this[Prefs._RefreshRate] * 1000 );
|
||||
} else {
|
||||
clearInterval(this._periodic_refresh);
|
||||
this._periodic_refresh = null;
|
||||
}
|
||||
},
|
||||
|
||||
periodicRefresh: function() {
|
||||
// Note: 'this' != 'transmission instance' since it is being called by setInterval
|
||||
if (!transmission._periodicRefreshIterations)
|
||||
transmission._periodicRefreshIterations = 0;
|
||||
|
||||
remote.loadTorrents(transmission._periodicRefreshIterations++ % 10 == 0);
|
||||
},
|
||||
|
||||
scheduleFileRefresh: function() {
|
||||
this._periodicRefreshIterations = 0;
|
||||
},
|
||||
@@ -1094,87 +1090,91 @@ Transmission.prototype =
|
||||
this.setFilter( Prefs._FilterAll );
|
||||
},
|
||||
|
||||
updateTorrentsData: function( torrent_list ) {
|
||||
refreshTorrents: function() {
|
||||
var tr = this;
|
||||
jQuery.each( torrent_list, function() {
|
||||
this.remote.getUpdatedDataFor('recently-active', function(active, removed){ tr.updateTorrentsData(active, removed); });
|
||||
},
|
||||
|
||||
updateTorrentsData: function( active, removed_ids ) {
|
||||
var tr = this;
|
||||
var new_torrent_ids = [];
|
||||
var refresh_files_for = [];
|
||||
jQuery.each( active, function() {
|
||||
var t = Torrent.lookup(tr._torrents, this.id);
|
||||
if (t) t.refresh(this);
|
||||
if (t){
|
||||
t.refresh(this);
|
||||
if(t.isSelected())
|
||||
refresh_files_for.push(t.id());
|
||||
}
|
||||
else
|
||||
new_torrent_ids.push(this.id);
|
||||
} );
|
||||
|
||||
tr.remote.loadTorrentFiles( refresh_files_for );
|
||||
|
||||
if(new_torrent_ids.length > 0)
|
||||
tr.remote.getInitialDataFor(new_torrent_ids, function(torrents){ tr.addTorrents(torrents) } );
|
||||
|
||||
var removedAny = tr.deleteTorrents(removed_ids);
|
||||
|
||||
if( ( new_torrent_ids.length != 0 ) || removedAny ) {
|
||||
tr.hideiPhoneAddressbar();
|
||||
tr.deselectAll( true );
|
||||
}
|
||||
|
||||
this.refilter();
|
||||
},
|
||||
|
||||
updateTorrentsFileData: function( torrents ){
|
||||
var tr = this;
|
||||
jQuery.each( torrents, function() {
|
||||
var t = Torrent.lookup(tr._torrents, this.id);
|
||||
if (t)
|
||||
t.refreshFileData(this);
|
||||
} );
|
||||
},
|
||||
|
||||
/*
|
||||
* Process got some new torrent data from the server
|
||||
*/
|
||||
updateAllTorrents: function( torrent_list ) {
|
||||
var torrent_data;
|
||||
var new_torrents = [];
|
||||
var torrent_ids = [];
|
||||
var handled = [];
|
||||
|
||||
// refresh existing torrents
|
||||
this.updateTorrentsData( torrent_list );
|
||||
|
||||
// partition existing and new torrents
|
||||
|
||||
for( var i=0, len=torrent_list.length; i<len; ++i ) {
|
||||
var data = torrent_list[i];
|
||||
var t = Torrent.lookup( this._torrents, data.id );
|
||||
if( !t )
|
||||
new_torrents.push( data );
|
||||
else {
|
||||
handled.push( t );
|
||||
}
|
||||
}
|
||||
|
||||
// Add any torrents that aren't already being displayed
|
||||
// if file data is available
|
||||
if( new_torrents.length ) {
|
||||
if (data.files) {
|
||||
for( var i=0, len=new_torrents.length; i<len; ++i ) {
|
||||
var t = new Torrent( this, new_torrents[i] );
|
||||
this._torrents.push( t );
|
||||
handled.push( t );
|
||||
}
|
||||
this._torrents.sort( Torrent.compareById );
|
||||
} else {
|
||||
// There are new torrents available
|
||||
// pick them up on the next refresh
|
||||
this.scheduleFileRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any torrents that weren't in the refresh list
|
||||
|
||||
initalizeAllTorrents: function(){
|
||||
var tr = this;
|
||||
this.remote.getInitialDataFor( null ,function(torrents) { tr.addTorrents(torrents); } );
|
||||
},
|
||||
|
||||
addTorrents: function( new_torrents ){
|
||||
var tr = this;
|
||||
|
||||
$.each( new_torrents, function(){
|
||||
var torrent = this;
|
||||
tr._torrents.push( new Torrent( tr, torrent ) );
|
||||
});
|
||||
|
||||
this.refilter();
|
||||
},
|
||||
|
||||
deleteTorrents: function(torrent_ids){
|
||||
if(typeof torrent_ids == 'undefined')
|
||||
return false;
|
||||
var tr = this;
|
||||
var removedAny = false;
|
||||
handled.sort( Torrent.compareById ); // for Torrent.indexOf
|
||||
var allTorrents = this._torrents.clone();
|
||||
for( var i=0, len=allTorrents.length; i<len; ++i ) {
|
||||
var t = allTorrents[i];
|
||||
if( Torrent.indexOf( handled, t.id() ) == -1 ) {
|
||||
var pos = Torrent.indexOf( this._torrents, t.id( ) );
|
||||
var e = this._torrents[pos].element();
|
||||
if( e ) {
|
||||
delete e._torrent;
|
||||
e.hide( );
|
||||
}
|
||||
t.hideFileList();
|
||||
this._torrents.splice( pos, 1 );
|
||||
$.each( torrent_ids, function(index, id){
|
||||
var torrent = Torrent.lookup(tr._torrents, id);
|
||||
|
||||
if(torrent) {
|
||||
removedAny = true;
|
||||
var e = torrent.element();
|
||||
if( e ) {
|
||||
var row_index = tr.getTorrentIndex(tr._rows, torrent);
|
||||
delete e._torrent; //remove circular refernce to help IE garbage collect
|
||||
tr._rows.splice(row_index, 1)
|
||||
e.remove();
|
||||
}
|
||||
|
||||
var pos = Torrent.indexOf( tr._torrents, torrent.id( ) );
|
||||
torrent.hideFileList();
|
||||
tr._torrents.splice( pos, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( ( new_torrents.length != 0 ) || removedAny ) {
|
||||
this.hideiPhoneAddressbar();
|
||||
this.deselectAll( true );
|
||||
}
|
||||
|
||||
// FIXME: not sure if this is possible in RPC
|
||||
// Update the disk space remaining
|
||||
//var disk_space_msg = 'Free Space: '
|
||||
//+ Math.formatBytes(data.free_space_bytes)
|
||||
//+ ' (' + data.free_space_percent + '% )';
|
||||
//setInnerHTML( $('div#disk_space_container')[0], disk_space_msg );
|
||||
|
||||
this.refilter( );
|
||||
});
|
||||
|
||||
return removedAny;
|
||||
},
|
||||
|
||||
/*
|
||||
@@ -1251,7 +1251,7 @@ Transmission.prototype =
|
||||
args.dataType = 'xml';
|
||||
args.iframe = true;
|
||||
args.success = function( data ) {
|
||||
tr.remote.loadTorrents( true );
|
||||
tr.refreshTorrents();
|
||||
tr.togglePeriodicRefresh( true );
|
||||
};
|
||||
tr.togglePeriodicRefresh( false );
|
||||
|
||||
@@ -96,38 +96,49 @@ TransmissionRemote.prototype =
|
||||
} );
|
||||
},
|
||||
|
||||
loadTorrents: function(update_files) {
|
||||
var tr = this._controller;
|
||||
getInitialDataFor: function(torrent_ids, callback) {
|
||||
var o = {
|
||||
method: 'torrent-get',
|
||||
arguments: { fields: [
|
||||
'addedDate', 'announceURL', 'comment', 'creator',
|
||||
arguments: {
|
||||
fields: [ 'addedDate', 'announceURL', 'comment', 'creator',
|
||||
'dateCreated', 'downloadedEver', 'error', 'errorString',
|
||||
'eta', 'hashString', 'haveUnchecked', 'haveValid', 'id',
|
||||
'isPrivate', 'leechers', 'leftUntilDone', 'name',
|
||||
'peersConnected', 'peersGettingFromUs', 'peersSendingToUs',
|
||||
'rateDownload', 'rateUpload', 'seeders', 'sizeWhenDone',
|
||||
'status', 'swarmSpeed', 'totalSize', 'uploadedEver' ]
|
||||
'status', 'swarmSpeed', 'totalSize', 'uploadedEver', 'files', 'fileStats' ]
|
||||
}
|
||||
};
|
||||
if (update_files) {
|
||||
o.arguments.fields.push('files');
|
||||
o.arguments.fields.push('wanted');
|
||||
o.arguments.fields.push('priorities');
|
||||
}
|
||||
this.sendRequest( o, function(data) {
|
||||
tr.updateAllTorrents( data.arguments.torrents );
|
||||
} );
|
||||
|
||||
if(torrent_ids)
|
||||
o.arguments.ids = torrent_ids;
|
||||
|
||||
this.sendRequest( o, function(data){ callback(data.arguments.torrents)} );
|
||||
},
|
||||
|
||||
|
||||
getUpdatedDataFor: function(torrent_ids, callback) {
|
||||
var o = {
|
||||
method: 'torrent-get',
|
||||
arguments: {
|
||||
'ids': torrent_ids,
|
||||
fields: [ 'id', 'downloadedEver', 'error', 'errorString',
|
||||
'eta', 'haveUnchecked', 'haveValid', 'leechers', 'leftUntilDone',
|
||||
'peersConnected', 'peersGettingFromUs', 'peersSendingToUs',
|
||||
'rateDownload', 'rateUpload', 'seeders',
|
||||
'status', 'swarmSpeed', 'uploadedEver' ]
|
||||
}
|
||||
};
|
||||
|
||||
this.sendRequest( o, function(data){ callback(data.arguments.torrents, data.arguments.removed)} );
|
||||
},
|
||||
|
||||
loadTorrentFiles: function( torrent_ids ) {
|
||||
var tr = this._controller;
|
||||
this.sendRequest( {
|
||||
method: 'torrent-get',
|
||||
arguments: { fields: [ 'files', 'wanted', 'priorities'] },
|
||||
ids: torrent_ids
|
||||
arguments: { fields: [ 'id', 'fileStats'], ids: torrent_ids },
|
||||
}, function(data) {
|
||||
tr.updateTorrentsData( data.arguments.torrents );
|
||||
tr.updateTorrentsFileData( data.arguments.torrents );
|
||||
} );
|
||||
},
|
||||
|
||||
@@ -154,7 +165,7 @@ TransmissionRemote.prototype =
|
||||
for( var i=0, len=torrents.length; i<len; ++i )
|
||||
o.arguments.ids.push( torrents[i].id() );
|
||||
this.sendRequest( o, function( ) {
|
||||
remote.loadTorrents();
|
||||
remote._controller.refreshTorrents();
|
||||
} );
|
||||
},
|
||||
|
||||
@@ -181,7 +192,7 @@ TransmissionRemote.prototype =
|
||||
for( var i=0, len=torrents.length; i<len; ++i )
|
||||
o.arguments.ids.push( torrents[i].id() );
|
||||
this.sendRequest( o, function( ) {
|
||||
remote.loadTorrents();
|
||||
remote._controller.refreshTorrents();
|
||||
} );
|
||||
},
|
||||
verifyTorrents: function( torrents ) {
|
||||
@@ -198,7 +209,7 @@ TransmissionRemote.prototype =
|
||||
};
|
||||
|
||||
this.sendRequest(o, function() {
|
||||
remote.loadTorrents();
|
||||
remote._controller.refreshTorrents();
|
||||
} );
|
||||
},
|
||||
savePrefs: function( args ) {
|
||||
|
||||
Reference in New Issue
Block a user