]> git.neil.brown.name Git - edlib.git/commitdiff
notmuch: update queries when not displayed.
authorNeilBrown <neil@brown.name>
Tue, 17 May 2022 23:45:14 +0000 (09:45 +1000)
committerNeilBrown <neil@brown.name>
Sat, 3 Sep 2022 06:49:08 +0000 (16:49 +1000)
I don't like the small delay when visiting a query that has new
messages.
But I don't want to pay the price of always updating in the background
even when I'm not looking at a query.
So track updates for the first 5 minutes, then assume the query
isn't interesting and stop updating.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
python/module-notmuch.py

index f276c6a3307d635013b11e7d0b3144346e630734..92a669da469fc8a18ec67cfd8ae6556138c6851f 100644 (file)
@@ -32,7 +32,7 @@ Bugs to be fixed
 ----------------
 
 - [ ] accessing document list can be slow.  Same for large directories
-- [ ] queries don't update in the background - they used to
+- [X] queries don't update in the background - they used to
 - [ ] images in email message should never be scaled up
 - [ ] marks sometimes get out of order in email query list
 - [ ] C-y sometimes yanks something strange, A-y then needed.
index 87196b5300b83dbdad237d27da83e2bd3f56ec3d..97bb99ba9910f41664e5384bd96227932b68504f 100644 (file)
@@ -655,6 +655,7 @@ class notmuch_main(edlib.Doc):
             nm.call("doc:notmuch:query:reload")
         elif nm['need-update'] or int(nm['last-refresh']) + 60 < int(time.time()):
             nm.call("doc:notmuch:query-refresh")
+        nm['background-update'] = "0"
         if comm2:
             comm2("callback", focus, nm)
         return 1
@@ -805,14 +806,29 @@ class notmuch_main(edlib.Doc):
             q = self.changed_queries.pop(0)
             for c in self.container.children():
                 if c['qname'] == q:
-                    if c.notify("doc:notify-viewers") == 0:
-                        # Just mark for refresh-on-visit
-                        c.call("doc:set:need-update", "true")
-                    else:
+                    if c.notify("doc:notify-viewers") > 0:
+                        # there are viewers, so just do a refresh.
                         self.querying = True
                         c("doc:notmuch:query-refresh")
                         # will get callback when time to continue
                         return
+                    elif int(c['background-update']) == 0:
+                        # First update with no viewers - full refresh
+                        c.call("doc:set:background-update",
+                               "%d" % int(time.time()))
+                        self.querying = True
+                        c("doc:notmuch:query:reload")
+                        # will get callback when time to continue
+                        return
+                    elif int(time.time()) - int(c['background-update']) < 5*60:
+                        # less than 5 minutes, keep updating
+                        self.querying = True
+                        c("doc:notmuch:query-refresh")
+                        # will get callback when time to continue
+                        return
+                    else:
+                        # Just mark for refresh-on-visit
+                        c.call("doc:set:need-update", "true")
 
 # notmuch_query document
 # a mark.pos is a list of thread-id and message-id.