[polari/wip/fmuellner/combined-gsoc: 10/136] chatView: Postpone fetching backlog until mapped



commit e83deeed67c6e2042f01222b62cd0778e6fc3720
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri May 20 23:54:23 2016 +0200

    chatView: Postpone fetching backlog until mapped
    
    Tracker (or more precisely: threading restrictions imposed by the
    underlying sqlite database) becomes a bottleneck when running too
    many queries simultaneously. Depending on the number of channels,
    this can be quite noticeable when fetching backlogs for all channels
    on startup. Avoid this by only fetching the initial backlog when
    mapping the chat log for the first time.

 src/chatView.js |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index b3c9cd4..07375de 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -293,6 +293,7 @@ const ChatView = new Lang.Class({
         this._state = { lastNick: null, lastTimestamp: 0, lastStatusGroup: 0 };
         this._active = false;
         this._toplevelFocus = false;
+        this._fetchingBacklog = false;
         this._joinTime = 0;
         this._maxNickChars = MAX_NICK_CHARS;
         this._hoveredButtonTags = [];
@@ -301,6 +302,7 @@ const ChatView = new Lang.Class({
         this._pendingLogs = [];
         this._initialPending = [];
         this._statusCount = { left: 0, joined: 0, total: 0 };
+        this._logWalker = null;
 
         this._room.account.connect('notify::nickname', Lang.bind(this,
             function() {
@@ -308,13 +310,6 @@ const ChatView = new Lang.Class({
             }));
         this._updateMaxNickChars(this._room.account.nickname.length);
 
-        let logManager = LogManager.getDefault();
-        this._logWalker = logManager.walkEvents(room.account, room.channel_name);
-
-        this._fetchingBacklog = true;
-        this._logWalker.getEvents(NUM_INITIAL_LOG_EVENTS,
-                                  Lang.bind(this, this._onLogEventsReady));
-
         this._autoscroll = true;
 
         this._app = Gio.Application.get_default();
@@ -597,11 +592,25 @@ const ChatView = new Lang.Class({
         this._view.left_margin = MARGIN + totalWidth;
     },
 
+    _ensureLogWalker: function() {
+        if (this._logWalker)
+            return;
+
+        let logManager = LogManager.getDefault();
+        this._logWalker = logManager.walkEvents(this._room.account,
+                                                this._room.channel_name);
+
+        this._fetchingBacklog = true;
+        this._logWalker.getEvents(NUM_INITIAL_LOG_EVENTS,
+                                  Lang.bind(this, this._onLogEventsReady));
+    },
+
     _updateActive: function() {
         let active = this.get_mapped();
         if (this._active == active)
             return;
         this._active = active;
+        this._ensureLogWalker();
         this._checkMessages();
     },
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]