From f4418ae88482d01e0e2fe38a5963f5a4c21f8048 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 22 Feb 2018 12:52:30 +1100 Subject: [PATCH] PERF: fast docking of timeline so it does not overlap In the past we debounced all dock check this causes situations where sometimes timeline would not dock in time especially on slow computers This works around it by performing the dock by hand. Also there was missing integer casting causing over aggressive re-rendering --- .../discourse/components/topic-timeline.js.es6 | 16 ++++++++++++++-- .../javascripts/discourse/mixins/docking.js.es6 | 6 ++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 b/app/assets/javascripts/discourse/components/topic-timeline.js.es6 index c693fd9c942..b89f8041947 100644 --- a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-timeline.js.es6 @@ -47,6 +47,17 @@ export default MountWidget.extend(Docking, { this.queueRerender(); }, + fastDockCheck(){ + // we need to dock super fast here, avoid any slow methods + // this is not debounced + const offset = window.pageYOffset; + + if (offset && this.fastDockAt && offset > this.fastDockAt) { + this.fastDockAt = null; + $('.timeline-container').addClass('timeline-docked timeline-docked-bottom'); + } + }, + dockCheck(info) { const mainOffset = $('#main').offset(); const offsetTop = mainOffset ? mainOffset.top : 0; @@ -62,13 +73,14 @@ export default MountWidget.extend(Docking, { this.dockBottom = false; if (posTop < topicTop) { - this.dockAt = topicTop; + this.dockAt = parseInt(topicTop, 10); } else if (pos > topicBottom + footerHeight) { - this.dockAt = (topicBottom - timelineHeight) + footerHeight; + this.dockAt = parseInt((topicBottom - timelineHeight) + footerHeight, 10); this.dockBottom = true; if (this.dockAt < 0) { this.dockAt = 0; } } else { this.dockAt = null; + this.fastDockAt = parseInt(topicBottom - timelineHeight + footerHeight - offsetTop, 10); } if (this.dockAt !== prev) { diff --git a/app/assets/javascripts/discourse/mixins/docking.js.es6 b/app/assets/javascripts/discourse/mixins/docking.js.es6 index 4b2505b1518..2a0fc36fa05 100644 --- a/app/assets/javascripts/discourse/mixins/docking.js.es6 +++ b/app/assets/javascripts/discourse/mixins/docking.js.es6 @@ -12,6 +12,12 @@ export default Ember.Mixin.create({ init() { this._super(); this.queueDockCheck = () => { + + // we want to do a very fast non-debounced check first + if (this.fastDockCheck) { + this.fastDockCheck(); + } + Ember.run.debounce(this, this.safeDockCheck, 5); }; },