summaryrefslogtreecommitdiff
path: root/alot/commands
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-02-07 10:01:43 +0100
committerAnton Khirnov <anton@khirnov.net>2021-02-07 10:01:43 +0100
commit0da20384169847aebe2ca4aa70557bf9cb726c48 (patch)
treefb459f493bcb1d2462bf361e14f83d570fa79373 /alot/commands
parent2f112621568fa7f8e90e59176dea905603986609 (diff)
commands/search: refactor applying the tag command
Apply toggle as a single db write rather than two.
Diffstat (limited to 'alot/commands')
-rw-r--r--alot/commands/search.py39
1 files changed, 22 insertions, 17 deletions
diff --git a/alot/commands/search.py b/alot/commands/search.py
index 9e4a3688..79aaee56 100644
--- a/alot/commands/search.py
+++ b/alot/commands/search.py
@@ -175,24 +175,29 @@ class TagCommand(Command):
if not self._thread:
testquery += ' and (%s)' % searchbuffer.querystring
+ if self._action == 'add':
+ task = ui.dbman.tags_add(testquery, self._tags)
+ if self._action == 'set':
+ task = ui.dbman.tags_set(testquery, self._tags)
+ elif self._action == 'remove':
+ task = ui.dbman.tags_remove(testquery, self._tags)
+ elif self._action == 'toggle':
+ if not self._all_threads:
+ to_remove = set()
+ to_add = set()
+ for t in self._tags:
+ if t in thread.get_tags():
+ to_remove.add(t)
+ else:
+ to_add.add(t)
+
+ write = ui.dbman.db_write_create()
+ write.queue_tag_remove(to_remove, 'thread:' + thread.id)
+ write.queue_tag_add(to_add, 'thread:' + thread.id)
+ task = write.apply()
+
try:
- if self._action == 'add':
- await ui.dbman.tags_add(testquery, self._tags)
- if self._action == 'set':
- await ui.dbman.tags_set(testquery, self._tags)
- elif self._action == 'remove':
- await ui.dbman.tags_remove(testquery, self._tags)
- elif self._action == 'toggle':
- if not self._all_threads:
- to_remove = set()
- to_add = set()
- for t in self._tags:
- if t in thread.get_tags():
- to_remove.add(t)
- else:
- to_add.add(t)
- await thread.tags_remove(to_remove)
- await thread.tags_add(to_add)
+ await task
except DatabaseROError:
ui.notify('index in read-only mode', priority='error')
return