[PATCH 2/2] lib/n_d_remove_message: do not remove unique filename

Subject: [PATCH 2/2] lib/n_d_remove_message: do not remove unique filename

Date: Thu, 20 Jul 2023 09:08:01 -0300

To: notmuch@notmuchmail.org

Cc: ukleinek@debian.org

From: David Bremner


It is wasteful to remove a filename term when the whole message
document is about to be removed from the database. Profiling with perf
shows this takes a significant portion of the time when cleaning up
removed files in the database.

The logic of n_d_remove_message becomes a bit more convoluted here in
order to make the change minimal.

It is possible that this function can be further optimized, since the
expansion of filename terms into filenames is probably not needed
here.
---
 lib/database.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/database.cc b/lib/database.cc
index 6987e2f4..737a3f30 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1454,7 +1454,9 @@ notmuch_database_remove_message (notmuch_database_t *notmuch,
 							&message);
 
     if (status == NOTMUCH_STATUS_SUCCESS && message) {
-	status = _notmuch_message_remove_filename (message, filename);
+	if (notmuch_message_count_files (message) > 1) {
+	    status = _notmuch_message_remove_filename (message, filename);
+	}
 	if (status == NOTMUCH_STATUS_SUCCESS)
 	    status = _notmuch_message_delete (message);
 	else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
-- 
2.40.1

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: