более масштабируемое обновление раздач

This commit is contained in:
Alexey Kasyanchuk 2017-01-09 17:23:49 +03:00
parent 1bffb33b70
commit 96196d1e17

View File

@ -177,12 +177,24 @@ export default class RecentTorrents extends Component {
this.forceUpdate(); this.forceUpdate();
} }
this.displayNewTorrent = setInterval(() => { this.displayNewTorrent = () => {
if(this.displayQueue.length == 0) if(!this.displayNewTorrent) {
return; return;
}
if(this.state.pause) if(this.displayQueue.length == 0) {
setTimeout(this.displayNewTorrent, 1000);
return; return;
}
let speed = 850 - (((this.displayQueue.length / 100)|0) * 100)
if(speed < 10)
speed = 10;
if(this.state.pause) {
setTimeout(this.displayNewTorrent, speed);
return;
}
let torrent = this.displayQueue.shift(); let torrent = this.displayQueue.shift();
this.torrents.unshift(torrent); this.torrents.unshift(torrent);
@ -192,7 +204,9 @@ export default class RecentTorrents extends Component {
} }
this.forceUpdate(); this.forceUpdate();
}, 850); setTimeout(this.displayNewTorrent, speed);
}
this.displayNewTorrent();
}); });
this.newTorrentFunc = (torrent) => { this.newTorrentFunc = (torrent) => {
this.displayQueue.push(torrent); this.displayQueue.push(torrent);
@ -221,7 +235,7 @@ export default class RecentTorrents extends Component {
if(this.tracketUpdate) if(this.tracketUpdate)
window.torrentSocket.off('trackerTorrentUpdate', this.tracketUpdate); window.torrentSocket.off('trackerTorrentUpdate', this.tracketUpdate);
if(this.displayNewTorrent) if(this.displayNewTorrent)
clearInterval(this.displayNewTorrent); delete this.displayNewTorrent;
} }
render() { render() {
if(!this.torrents || this.torrents.length == 0) if(!this.torrents || this.torrents.length == 0)