Skip to content

Commit

Permalink
Merge pull request #768 from matrix-org/kegan/memleaks-are-bad-mkay
Browse files Browse the repository at this point in the history
Add canResetTimeline callback and thread it through to TimelinePanel
  • Loading branch information
kegsay committed Mar 22, 2017
2 parents fc9928c + 4cebded commit 3d71cb8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/components/structures/LoggedInView.js
Expand Up @@ -81,6 +81,13 @@ export default React.createClass({
return this._scrollStateMap[roomId];
},

canResetTimelineInRoom: function(roomId) {
if (!this.refs.roomView) {
return true;
}
return this.refs.roomView.canResetTimeline();
},

_onKeyDown: function(ev) {
/*
// Remove this for now as ctrl+alt = alt-gr so this breaks keyboards which rely on alt-gr for numbers
Expand Down
24 changes: 23 additions & 1 deletion src/components/structures/MatrixChat.js
Expand Up @@ -806,9 +806,31 @@ module.exports = React.createClass({
* (useful for setting listeners)
*/
_onWillStartClient() {
var self = this;
var cli = MatrixClientPeg.get();

var self = this;
// Allow the JS SDK to reap timeline events. This reduces the amount of
// memory consumed as the JS SDK stores multiple distinct copies of room
// state (each of which can be 10s of MBs) for each DISJOINT timeline. This is
// particularly noticeable when there are lots of 'limited' /sync responses
// such as when laptops unsleep.
// https://github.com/vector-im/riot-web/issues/3307#issuecomment-282895568
cli.setCanResetTimelineCallback(function(roomId) {
console.log("Request to reset timeline in room ", roomId, " viewing:", self.state.currentRoomId);
if (roomId !== self.state.currentRoomId) {
// It is safe to remove events from rooms we are not viewing.
return true;
}
// We are viewing the room which we want to reset. It is only safe to do
// this if we are not scrolled up in the view. To find out, delegate to
// the timeline panel. If the timeline panel doesn't exist, then we assume
// it is safe to reset the timeline.
if (!self.refs.loggedInView) {
return true;
}
return self.refs.loggedInView.canResetTimelineInRoom(roomId);
});

cli.on('sync', function(state, prevState) {
self.updateStatusIndicator(state, prevState);
if (state === "SYNCING" && prevState === "SYNCING") {
Expand Down
7 changes: 7 additions & 0 deletions src/components/structures/RoomView.js
Expand Up @@ -490,6 +490,13 @@ module.exports = React.createClass({
}
},

canResetTimeline: function() {
if (!this.refs.messagePanel) {
return true;
}
return this.refs.messagePanel.canResetTimeline();
},

// called when state.room is first initialised (either at initial load,
// after a successful peek, or after we join the room).
_onRoomLoaded: function(room) {
Expand Down
4 changes: 4 additions & 0 deletions src/components/structures/TimelinePanel.js
Expand Up @@ -431,6 +431,10 @@ var TimelinePanel = React.createClass({
}
},

canResetTimeline: function() {
return this.refs.messagePanel && this.refs.messagePanel.isAtBottom();
},

onRoomRedaction: function(ev, room) {
if (this.unmounted) return;

Expand Down
3 changes: 2 additions & 1 deletion src/components/structures/UploadBar.js
Expand Up @@ -25,12 +25,13 @@ module.exports = React.createClass({displayName: 'UploadBar',
},

componentDidMount: function() {
dis.register(this.onAction);
this.dispatcherRef = dis.register(this.onAction);
this.mounted = true;
},

componentWillUnmount: function() {
this.mounted = false;
dis.unregister(this.dispatcherRef);
},

onAction: function(payload) {
Expand Down

0 comments on commit 3d71cb8

Please sign in to comment.