[gnome-shell/wip/fmuellner/fix-clear-events: 30/30] events: Re-use event messages where possible
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/fmuellner/fix-clear-events: 30/30] events: Re-use event messages where possible
- Date: Fri, 13 Jul 2018 20:14:55 +0000 (UTC)
commit e7f2e924100495969d62e91574e03fc0e6fc0112
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Jun 9 13:23:35 2018 +0200
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]