более редкий вызов обновлений

This commit is contained in:
Alexey Kasyanchuk
2017-01-19 19:52:21 +03:00
parent 671c836e24
commit 354cb5afd4

View File

@ -167,9 +167,11 @@ export default class RecentTorrents extends Component {
constructor() { constructor() {
super() super()
this.torrents = []; this.torrents = [];
this.torrentsAssoc = {};
this.displayQueue = []; this.displayQueue = [];
this.displayQueueAssoc = {}; this.displayQueueAssoc = {};
this.maxDisplaySize = 1000; this.maxQueueSize = 1000;
this.maxDisplaySize = 10;
this.state = { this.state = {
pause: false, pause: false,
searchingIndicator: false searchingIndicator: false
@ -201,15 +203,26 @@ export default class RecentTorrents extends Component {
let torrent = this.displayQueue.shift(); let torrent = this.displayQueue.shift();
this.torrents.unshift(torrent); this.torrents.unshift(torrent);
if(this.torrents.length > 10) { this.torrentsAssoc[torrent.hash] = torrent;
if(this.torrents.length > this.maxDisplaySize) {
let toDelete = this.torrents.pop() let toDelete = this.torrents.pop()
delete this.torrentsAssoc[toDelete.hash];
delete this.displayQueueAssoc[toDelete.hash]; delete this.displayQueueAssoc[toDelete.hash];
} }
this.displayTorrentCounterValue = this.displayQueue.length;
this.forceUpdate(); this.forceUpdate();
setTimeout(this.displayNewTorrent, speed); setTimeout(this.displayNewTorrent, speed);
} }
this.displayNewTorrent(); this.displayNewTorrent();
this.displayTorrentCounterValue = 0;
this.displayTorrentCounter = setInterval(() => {
if(this.displayTorrentCounterValue != this.displayQueue.length) {
this.displayTorrentCounterValue = this.displayQueue.length;
this.forceUpdate();
}
}, 40);
}, () => { }, () => {
this.setState({ this.setState({
searchingIndicator: true searchingIndicator: true
@ -220,10 +233,9 @@ export default class RecentTorrents extends Component {
}); });
})); }));
this.newTorrentFunc = (torrent) => { this.newTorrentFunc = (torrent) => {
if(this.displayQueue.length < this.maxDisplaySize) { if(this.displayQueue.length < this.maxQueueSize) {
this.displayQueue.push(torrent); this.displayQueue.push(torrent);
this.displayQueueAssoc[torrent.hash] = torrent; this.displayQueueAssoc[torrent.hash] = torrent;
this.forceUpdate();
} }
}; };
window.torrentSocket.on('newTorrent', this.newTorrentFunc); window.torrentSocket.on('newTorrent', this.newTorrentFunc);
@ -232,9 +244,11 @@ export default class RecentTorrents extends Component {
if(statistic.hash in this.displayQueueAssoc) if(statistic.hash in this.displayQueueAssoc)
{ {
Object.assign(this.displayQueueAssoc[statistic.hash], statistic); Object.assign(this.displayQueueAssoc[statistic.hash], statistic);
if(statistic.hash in this.torrentsAssoc) {
this.forceUpdate(); this.forceUpdate();
} }
} }
}
window.torrentSocket.on('trackerTorrentUpdate', this.tracketUpdate); window.torrentSocket.on('trackerTorrentUpdate', this.tracketUpdate);
} }
pauseAndContinue() { pauseAndContinue() {
@ -249,6 +263,8 @@ export default class RecentTorrents extends Component {
window.torrentSocket.off('trackerTorrentUpdate', this.tracketUpdate); window.torrentSocket.off('trackerTorrentUpdate', this.tracketUpdate);
if(this.displayNewTorrent) if(this.displayNewTorrent)
delete this.displayNewTorrent; delete this.displayNewTorrent;
if(this.displayTorrentCounter)
clearInterval(this.displayTorrentCounter);
} }
render() { render() {
const style = { const style = {