diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-07-31 09:08:48 -0700 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-01-10 11:10:40 +0100 |
commit | c79196b8b1c5eb99a2f240aaf0069853d798bdd0 (patch) | |
tree | 5852f43886237c3e245b687cabe8450fc8333fb5 /alot/buffers | |
parent | 47ebd7656057fadb5b627dfc1844bc09dc171ff2 (diff) |
db/manager: Drop async method
As far as I can tell using a separate process doesn't actually improve
performance, it makes it worse. The work that we're passing off to the
separate function isn't necessarily work that's well suited to being
handed off, there isn't a lot of computation and the objects that need
to be passed across the pipe are fairly large (at least when considering
a pipe). Converting the function to a generator gives better performance
and simplifies the implementation.
Diffstat (limited to 'alot/buffers')
-rw-r--r-- | alot/buffers/search.py | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/alot/buffers/search.py b/alot/buffers/search.py index c5b6bbcd..8cd76a87 100644 --- a/alot/buffers/search.py +++ b/alot/buffers/search.py @@ -8,16 +8,16 @@ from .buffer import Buffer from ..settings.const import settings from ..widgets.search import ThreadlineWidget -class PipeWalker(urwid.ListWalker): +class IterWalker(urwid.ListWalker): """ - urwid.ListWalker that reads next items from a pipe and wraps them in + urwid.ListWalker that reads next items from a generator and wraps them in ThreadlineWidget widgets for displaying """ _pipe = None _dbman = None - _pipe_eof = False + _iter_done = False # list of the thread IDs _tids = None @@ -26,9 +26,9 @@ class PipeWalker(urwid.ListWalker): _focus = None - def __init__(self, pipe, dbman): - self._pipe = pipe - self._dbman = dbman + def __init__(self, threads, dbman): + self._threads = threads + self._dbman = dbman self._tids = [] self._wgts = {} @@ -38,7 +38,7 @@ class PipeWalker(urwid.ListWalker): super().__init__() def __len__(self): - while not self._pipe_eof: + while not self._iter_done: self._get_next_item() return len(self._tids) @@ -58,7 +58,7 @@ class PipeWalker(urwid.ListWalker): if pos < 0: raise IndexError - while not self._pipe_eof and pos >= len(self._tids): + while not self._iter_done and pos >= len(self._tids): self._get_next_item() if pos >= len(self._tids): @@ -80,13 +80,13 @@ class PipeWalker(urwid.ListWalker): self._modified() def _get_next_item(self): - if self._pipe_eof: + if self._iter_done: return None try: - self._tids.append(self._pipe.recv()) - except EOFError: - self._pipe_eof = True + self._tids.append(next(self._threads)) + except StopIteration: + self._iter_done = True class SearchBuffer(Buffer): """shows a result list of threads for a query""" @@ -102,7 +102,6 @@ class SearchBuffer(Buffer): self.querystring = initialquery default_order = settings.get('search_threads_sort_order') self.sort_order = sort_order or default_order - self.proc = None # process that fills our pipe self.rebuild() super().__init__() @@ -132,21 +131,7 @@ class SearchBuffer(Buffer): info['result_count_positive'] = 's' if info['result_count'] > 1 else '' return info - def cleanup(self): - self.kill_filler_process() - - def kill_filler_process(self): - """ - terminates the process that fills this buffers - :class:`~alot.walker.PipeWalker`. - """ - if self.proc: - if self.proc.is_alive(): - self.proc.terminate() - def rebuild(self): - self.kill_filler_process() - exclude_tags = settings.get_notmuch_setting('search', 'exclude_tags') if exclude_tags: exclude_tags = frozenset([t for t in exclude_tags.split(';') if t]) @@ -157,9 +142,8 @@ class SearchBuffer(Buffer): self._thread_count_val = None try: - self.pipe, self.proc = self.dbman.get_threads(self.querystring, - self.sort_order, - exclude_tags) + threads = self.dbman.get_threads(self.querystring, self.sort_order, + exclude_tags) except NotmuchError: self.ui.notify('malformed query string: %s' % self.querystring, 'error') @@ -167,7 +151,7 @@ class SearchBuffer(Buffer): self.body = self.listbox return - self.threadlist = PipeWalker(self.pipe, self.dbman) + self.threadlist = IterWalker(threads, self.dbman) self.listbox = urwid.ListBox(self.threadlist) self.body = self.listbox |