mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
emacs: Use streaming S-expr parser for search
In addition to being the Right Thing to do, this noticeably improves the time taken to display the first page of search results, since it's roughly an order of magnitude faster than the JSON parser. Interestingly, it does *not* significantly improve the time to completely fill a large search buffer because for large search buffers, the cost of creating author invisibility overlays and inserting text (which slows down with more overlays) dominates. However, the time required to display the first page of results is generally more important to the user experience.
This commit is contained in:
parent
b89ffba301
commit
89efd5717a
2 changed files with 6 additions and 17 deletions
|
@ -58,6 +58,7 @@
|
||||||
(require 'notmuch-hello)
|
(require 'notmuch-hello)
|
||||||
(require 'notmuch-maildir-fcc)
|
(require 'notmuch-maildir-fcc)
|
||||||
(require 'notmuch-message)
|
(require 'notmuch-message)
|
||||||
|
(require 'notmuch-parser)
|
||||||
|
|
||||||
(defcustom notmuch-search-result-format
|
(defcustom notmuch-search-result-format
|
||||||
`(("date" . "%12s ")
|
`(("date" . "%12s ")
|
||||||
|
@ -809,13 +810,6 @@ non-authors is found, assume that all of the authors match."
|
||||||
(setq notmuch-search-target-thread "found")
|
(setq notmuch-search-target-thread "found")
|
||||||
(goto-char beg)))))
|
(goto-char beg)))))
|
||||||
|
|
||||||
(defun notmuch-search-show-error (string &rest objects)
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-max))
|
|
||||||
(insert "Error: Unexpected output from notmuch search:\n")
|
|
||||||
(insert (apply #'format string objects))
|
|
||||||
(insert "\n")))
|
|
||||||
|
|
||||||
(defun notmuch-search-process-filter (proc string)
|
(defun notmuch-search-process-filter (proc string)
|
||||||
"Process and filter the output of \"notmuch search\""
|
"Process and filter the output of \"notmuch search\""
|
||||||
(let ((results-buf (process-buffer proc))
|
(let ((results-buf (process-buffer proc))
|
||||||
|
@ -829,8 +823,7 @@ non-authors is found, assume that all of the authors match."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(insert string))
|
(insert string))
|
||||||
(notmuch-json-parse-partial-list 'notmuch-search-show-result
|
(notmuch-sexp-parse-partial-list 'notmuch-search-show-result
|
||||||
'notmuch-search-show-error
|
|
||||||
results-buf)))))
|
results-buf)))))
|
||||||
|
|
||||||
(defun notmuch-search-tag-all (&optional tag-changes)
|
(defun notmuch-search-tag-all (&optional tag-changes)
|
||||||
|
@ -933,7 +926,7 @@ Other optional parameters are used as follows:
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let ((proc (notmuch-start-notmuch
|
(let ((proc (notmuch-start-notmuch
|
||||||
"notmuch-search" buffer #'notmuch-search-process-sentinel
|
"notmuch-search" buffer #'notmuch-search-process-sentinel
|
||||||
"search" "--format=json" "--format-version=1"
|
"search" "--format=sexp" "--format-version=1"
|
||||||
(if oldest-first
|
(if oldest-first
|
||||||
"--sort=oldest-first"
|
"--sort=oldest-first"
|
||||||
"--sort=newest-first")
|
"--sort=newest-first")
|
||||||
|
|
10
test/emacs
10
test/emacs
|
@ -858,7 +858,7 @@ test_expect_success "Rendering HTML mail with images" \
|
||||||
test_begin_subtest "Search handles subprocess error exit codes"
|
test_begin_subtest "Search handles subprocess error exit codes"
|
||||||
cat > notmuch_fail <<EOF
|
cat > notmuch_fail <<EOF
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
echo This is output
|
echo '()'
|
||||||
exit 1
|
exit 1
|
||||||
EOF
|
EOF
|
||||||
chmod a+x notmuch_fail
|
chmod a+x notmuch_fail
|
||||||
|
@ -873,21 +873,19 @@ test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
|
||||||
(test-output))"
|
(test-output))"
|
||||||
sed -i -e 's/^\[.*\]$/[XXX]/' ERROR
|
sed -i -e 's/^\[.*\]$/[XXX]/' ERROR
|
||||||
test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\
|
test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\
|
||||||
Error: Unexpected output from notmuch search:
|
|
||||||
This is output
|
|
||||||
End of search results.
|
End of search results.
|
||||||
---
|
---
|
||||||
$PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)
|
$PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)
|
||||||
---
|
---
|
||||||
[XXX]
|
[XXX]
|
||||||
$PWD/notmuch_fail exited with status 1
|
$PWD/notmuch_fail exited with status 1
|
||||||
command: $PWD/notmuch_fail search --format\=json --format-version\=1 --sort\=newest-first tag\:inbox
|
command: $PWD/notmuch_fail search --format\=sexp --format-version\=1 --sort\=newest-first tag\:inbox
|
||||||
exit status: 1"
|
exit status: 1"
|
||||||
|
|
||||||
test_begin_subtest "Search handles subprocess warnings"
|
test_begin_subtest "Search handles subprocess warnings"
|
||||||
cat > notmuch_fail <<EOF
|
cat > notmuch_fail <<EOF
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
echo This is output
|
echo '()'
|
||||||
echo This is a warning >&2
|
echo This is a warning >&2
|
||||||
echo This is another warning >&2
|
echo This is another warning >&2
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -905,8 +903,6 @@ test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
|
||||||
(test-output))"
|
(test-output))"
|
||||||
sed -i -e 's/^\[.*\]$/[XXX]/' ERROR
|
sed -i -e 's/^\[.*\]$/[XXX]/' ERROR
|
||||||
test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\
|
test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\
|
||||||
Error: Unexpected output from notmuch search:
|
|
||||||
This is output
|
|
||||||
End of search results.
|
End of search results.
|
||||||
---
|
---
|
||||||
This is a warning (see *Notmuch errors* for more details)
|
This is a warning (see *Notmuch errors* for more details)
|
||||||
|
|
Loading…
Reference in a new issue