diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2016-12-19 16:11:58 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2016-12-21 17:14:04 -0800 |
commit | e1590f7d64f172015b74fca2454c70b9c5944b9e (patch) | |
tree | 1a0488dc037943e6164b5675c9e45f0080e3dcc6 /alot/db/thread.py | |
parent | 84bee04c1abae4f1832c158b505cb1b724a54f50 (diff) |
db/thread: Avoid intermediate data structure
This patch removes the need to create an intermediate dictionary while
calculating the authors of a thread, it does so by working directly with
the _authors list.
Diffstat (limited to 'alot/db/thread.py')
-rw-r--r-- | alot/db/thread.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/alot/db/thread.py b/alot/db/thread.py index ef9a0578..c0ee781a 100644 --- a/alot/db/thread.py +++ b/alot/db/thread.py @@ -1,7 +1,6 @@ # Copyright (C) 2011-2012 Patrick Totzke <patricktotzke@gmail.com> # This file is released under the GNU GPL, version 3 or a later revision. # For further details see the COPYING file -import operator from datetime import datetime from .message import Message @@ -156,19 +155,20 @@ class Thread(object): msgs = sorted(self.get_messages().iterkeys(), key=lambda m: m.get_date() or datetime.max) - seen = {} orderby = settings.get('thread_authors_order_by') + self._authors = [] if orderby == 'latest_message': - for i, m in enumerate(msgs): + for m in msgs: pair = m.get_author() - seen[pair] = i + if pair in self._authors: + self._authors.remove(pair) + self._authors.append(pair) else: # i.e. first_message - for i, m in enumerate(msgs): + for m in msgs: pair = m.get_author() - if pair not in seen: - seen[pair] = i - self._authors = [ name for name, addr in - sorted(seen.items(), key=operator.itemgetter(1)) ] + if pair not in self._authors: + self._authors.append(pair) + return self._authors def get_authors_string(self, own_addrs=None, replace_own=None): |