From 9c51c87d8c145990285643c89deec77263d3d416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sat, 9 Jun 2018 13:23:35 +0200 Subject: [PATCH] events: Re-use event messages where possible Destroying and recreating the entire events list on every change is not only wasteful, it also breaks the clear functionality as messages scheduled for removal are replaced with "new" messages after the first message has been removed. Address both issues by keeping track of all messages and re-use them whenever possible. https://gitlab.gnome.org/GNOME/gnome-shell/issues/325 --- js/ui/calendar.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/js/ui/calendar.js b/js/ui/calendar.js index a46017ad0..651aac610 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -821,6 +821,8 @@ var EventsSection = new Lang.Class({ this._desktopSettings.connect('changed', this._reloadEvents.bind(this)); this._eventSource = new EmptyEventSource(); + this._messageById = new Map(); + this.parent(); this._title = new St.Button({ style_class: 'events-section-title', @@ -875,20 +877,32 @@ var EventsSection = new Lang.Class({ this._reloading = true; - this._list.destroy_all_children(); - let periodBegin = _getBeginningOfDay(this._date); let periodEnd = _getEndOfDay(this._date); let events = this._eventSource.getEvents(periodBegin, periodEnd); + let ids = events.map(e => e.id); + this._messageById.forEach((message, id) => { + if (ids.includes(id)) + return; + this._messageById.delete(id); + this.removeMessage(message); + }); + for (let i = 0; i < events.length; i++) { let event = events[i]; - let message = new EventMessage(event, this._date); - message.connect('close', () => { - this._ignoreEvent(event); - }); - this.addMessage(message, false); + let message = this._messageById.get(event.id); + if (!message) { + message = new EventMessage(event, this._date); + message.connect('close', () => { + this._ignoreEvent(event); + }); + this._messageById.set(event.id, message); + this.addMessage(message, false); + } else { + this.moveMessage(message, i, false); + } } this._reloading = false;