From fce7fe43691de4abba399747cc00f9dbbb5840b8 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Tue, 10 Apr 2018 16:55:11 +0300 Subject: [PATCH] perf(top): less cpu usage on top page update --- src/app/top-page.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/top-page.js b/src/app/top-page.js index e4d1fb1..7a42e73 100644 --- a/src/app/top-page.js +++ b/src/app/top-page.js @@ -42,11 +42,20 @@ export default class TopPage extends Page { if(data && data.length > 0) { this.topTorrents[type] = this.topTorrents[type].concat(data); - this.forceUpdate() + this._update() } }) ) } + _update() + { + if(this.timeForce) + return + this.timeForce = setTimeout(() => { + delete this.timeForce + this.forceUpdate() + }, 550) + } componentDidMount() { super.componentDidMount(); @@ -59,7 +68,7 @@ export default class TopPage extends Page { return type = type ? type : 'main' this.topTorrents[type] = _.orderBy(_.unionBy(this.topTorrents[type], torrents, 'hash'), ['seeders'], ['desc']) - this.forceUpdate(); + this._update(); } window.torrentSocket.on('remoteTopTorrents', this.remoteTopTorrents); }