From c913c6b179973a310cb6c4fbbfc4adefad50f6e0 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 18 Mar 2021 16:54:54 +0100 Subject: db/manager: optimize database modifications Add only tags that are not present on the message, remove only tags that are present. Otherwise the no-op modification results in an actual db write, even though nothing changes. --- alot/db/manager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/alot/db/manager.py b/alot/db/manager.py index 148cfe2a..efd70e70 100644 --- a/alot/db/manager.py +++ b/alot/db/manager.py @@ -60,12 +60,14 @@ class _DBWriteList: def _do_tag_add(self, db, tags, query): for msg in db.messages(query): msg_tags = msg.tags - msg_tags |= tags + op_tags = tags - msg_tags + msg_tags |= op_tags def _do_tag_remove(self, db, tags, query): for msg in db.messages(query): msg_tags = msg.tags - msg_tags -= tags + op_tags = tags & msg_tags + msg_tags -= op_tags def _do_tag_set(self, db, tags, query): for msg in db.messages(query): -- cgit v1.2.3