diff options
Diffstat (limited to 'alot/db/manager.py')
-rw-r--r-- | alot/db/manager.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/alot/db/manager.py b/alot/db/manager.py index 4d9b5778..c4ec02d1 100644 --- a/alot/db/manager.py +++ b/alot/db/manager.py @@ -5,6 +5,7 @@ import abc import asyncio from contextlib import closing +from functools import partialmethod import logging import os @@ -154,15 +155,19 @@ class DBManager: def _db_ro(self): return closing(Database(path = self.path, mode = Database.MODE.READ_ONLY)) - def count_messages(self, querystring): - """returns number of messages that match `querystring`""" - with self._db_ro() as db: - return db.count_messages(querystring, exclude_tags = self._exclude_tags) + def _count(self, what, querystring): + try: + with self._db_ro() as db: + func = getattr(db, 'count_' +what) + return func(querystring, exclude_tags = self._exclude_tags) + except NotmuchError: + return -1 - def count_threads(self, querystring): - """returns number of threads that match `querystring`""" - with self._db_ro() as db: - return db.count_threads(querystring, exclude_tags = self._exclude_tags) + count_messages = partialmethod(_count, 'messages') + """returns number of messages that match `querystring`""" + + count_threads = partialmethod(_count, 'threads') + """returns number of threads that match `querystring`""" def _get_notmuch_thread(self, db, tid): """returns :class:`notmuch.database.Thread` with given id""" |