From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id cIOZIpRQdmBbjwAAgWs5BA (envelope-from ) for ; Wed, 14 Apr 2021 04:16:52 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id iJVmHJRQdmCsSQAAB5/wlQ (envelope-from ) for ; Wed, 14 Apr 2021 02:16:52 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B61041DB45 for ; Wed, 14 Apr 2021 04:16:51 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 02F772717C; Tue, 13 Apr 2021 22:16:39 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 89A3D1FBCE for ; Tue, 13 Apr 2021 22:16:34 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 5701B5FAA5; Tue, 13 Apr 2021 22:16:33 -0400 (EDT) Received: (nullmailer pid 1236639 invoked by uid 1000); Wed, 14 Apr 2021 02:16:30 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 2/2] WIP: replace use of queries in n_m_delete with postlist access Date: Tue, 13 Apr 2021 23:16:27 -0300 Message-Id: <20210414021627.1236560-3-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210414021627.1236560-1-david@tethera.net> References: <20210414021627.1236560-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: TGJUFJYMR4GWTBK5G65XOWDCZLVKECQW X-Message-ID-Hash: TGJUFJYMR4GWTBK5G65XOWDCZLVKECQW X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1618366612; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Rqpp/aXN2T6x5OkN6B40Q8fStFaCAaKjoS6nM2dKOIk=; b=kAX8nwoL/5vclk2ANo6c5ORJ0w61g67uzkvNpdubZz8N9gqS9zWOwDYgrV54NfgppZFID+ rtB+jVw8ISNce8GrOu9wLScKVRMNs7XyLpXDrslmJeDWacqguC1y6zs5legr6Y/Vl0YBmm tVZQqVKjKQiMpnnkY3LDi8OC8+I4O/a6J40YuO75+lsW/tfg8+Vby68ofl+13NisjKEInJ H27uZt3I5yIQobpLkgR+vnJN2S+nOE/7/xXgfv0eBIPxe9NQp4kD1mSb+vFHACtgjblDlJ yEq3deYkId2+hqDvwMWy6s1tRQi1vm11dNrMA8qmQOL4TuTyzBuFSe/taS1wbQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1618366612; a=rsa-sha256; cv=none; b=DsshVr2RqYFcfoORFUzpbRE76tFR6N6+VSLLrSVxSOzJ9x567a+UuEyN2pAekf4wm0SwQI TLA8RSqgILwameGjDYuONn89Kf1FqtyQBHCX/oJJBeEaJIc5ARDSRHM1X8PmPL8lXyH77s 7byksfvD8lzjOULzNWICvN3bZbct7G7btXvqakLDcESKjFcArCJLtpHXoBW/xKUQn00OQ9 HmSvjXMnVjihu3rbJtAwo0OW3N/+5YhmrUHPmipoIBkQMntysfhSzbOC2+JcK9hYW46zNS xrb186OHwFUS1d3V3gGVS+4B77MG+xcIoCpMVXYbsWbwTtuOXILT3zo9rClStg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 0.52 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: B61041DB45 X-Spam-Score: 0.52 X-Migadu-Scanner: scn0.migadu.com X-TUID: h/IvIkHREMZe This improves performance because it removes some interleaving of queries and deletions, which is causing a lot of time to be spenting checking for position information in the glass backend --- lib/message.cc | 68 +++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 0c2eeab5..42d56acb 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -1356,11 +1356,10 @@ notmuch_status_t _notmuch_message_delete (notmuch_message_t *message) { notmuch_status_t status; - const char *mid, *tid, *query_string; + const char *mid, *tid; notmuch_message_t *ghost; notmuch_private_status_t private_status; notmuch_database_t *notmuch; - notmuch_query_t *query; unsigned int count = 0; bool is_ghost; @@ -1382,16 +1381,33 @@ _notmuch_message_delete (notmuch_message_t *message) if (is_ghost) return NOTMUCH_STATUS_SUCCESS; - query_string = talloc_asprintf (message, "thread:%s", tid); - query = notmuch_query_create (notmuch, query_string); - if (query == NULL) - return NOTMUCH_STATUS_OUT_OF_MEMORY; - status = notmuch_query_count_messages (query, &count); - if (status) { - notmuch_query_destroy (query); - return status; + /* look for a non-ghost message in the same thread */ + try { + Xapian::PostingIterator thread_doc, thread_doc_end; + Xapian::PostingIterator mail_doc, mail_doc_end; + + _notmuch_database_find_doc_ids (message->notmuch, "thread", tid, &thread_doc, + &thread_doc_end); + _notmuch_database_find_doc_ids (message->notmuch, "type", "mail", &mail_doc, &mail_doc_end); + + while (count == 0 && + thread_doc != thread_doc_end && + mail_doc != mail_doc_end) { + thread_doc.skip_to (*mail_doc); + if (thread_doc != thread_doc_end) { + if (*thread_doc == *mail_doc) { + count++; + } else { + mail_doc.skip_to (*thread_doc); + if (mail_doc != mail_doc_end && *thread_doc == *mail_doc) + count++; + } + } + } + } catch (Xapian::Error &error) { + LOG_XAPIAN_EXCEPTION (message, error); + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; } - if (count > 0) { /* reintroduce a ghost in its place because there are still * other active messages in this thread: */ @@ -1410,27 +1426,21 @@ _notmuch_message_delete (notmuch_message_t *message) notmuch_message_destroy (ghost); status = COERCE_STATUS (private_status, "Error converting to ghost message"); } else { - /* the thread is empty; drop all ghost messages from it */ - notmuch_messages_t *messages; - status = _notmuch_query_search_documents (query, - "ghost", - &messages); - if (status == NOTMUCH_STATUS_SUCCESS) { - notmuch_status_t last_error = NOTMUCH_STATUS_SUCCESS; - while (notmuch_messages_valid (messages)) { - message = notmuch_messages_get (messages); - status = _notmuch_message_delete (message); - if (status) /* we'll report the last failure we see; - * if there is more than one failure, we - * forget about previous ones */ - last_error = status; - notmuch_message_destroy (message); - notmuch_messages_move_to_next (messages); + /* the thread now contains only ghosts: delete them */ + try { + Xapian::PostingIterator doc, doc_end; + + _notmuch_database_find_doc_ids (message->notmuch, "thread", tid, &doc, &doc_end); + + for (; doc != doc_end; doc++) { + message->notmuch->writable_xapian_db->delete_document (*doc); } - status = last_error; + } catch (Xapian::Error &error) { + LOG_XAPIAN_EXCEPTION (message, error); + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; } + } - notmuch_query_destroy (query); return status; } -- 2.30.2