[PATCH] RFC: all deleting all properties with a given key
[notmuch-archives.git] / c6 / 6a2e3272e3ba4a02ed65f7e18d7a985c8241f4
1 Return-Path: <bremner@tesseract.cs.unb.ca>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5  by arlo.cworth.org (Postfix) with ESMTP id D85946DE1785\r
6  for <notmuch@notmuchmail.org>; Fri,  5 Jun 2015 10:31:09 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.237\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.237 tagged_above=-999 required=5 tests=[AWL=0.227, \r
12  T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id JkPuUjrYLOn0 for <notmuch@notmuchmail.org>;\r
16  Fri,  5 Jun 2015 10:31:07 -0700 (PDT)\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
18  [87.98.215.224])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id 2AA5D6DE17E8\r
20  for <notmuch@notmuchmail.org>; Fri,  5 Jun 2015 10:31:01 -0700 (PDT)\r
21 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
22  4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
23  id 1Z0vQl-0002nX-CW; Fri, 05 Jun 2015 17:29:19 +0000\r
24 Received: (nullmailer pid 24248 invoked by uid 1000); Fri, 05 Jun 2015\r
25  17:28:42 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH 1/6] lib: Only sync modified message documents\r
29 Date: Fri,  5 Jun 2015 19:28:33 +0200\r
30 Message-Id: <1433525318-23756-2-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.1.4\r
32 In-Reply-To: <1433525318-23756-1-git-send-email-david@tethera.net>\r
33 References: <1432936375-astroid-4-0i1n6yczs2-1520@strange>\r
34  <1433525318-23756-1-git-send-email-david@tethera.net>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.18\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39  <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Fri, 05 Jun 2015 17:31:10 -0000\r
48 \r
49 From: Austin Clements <amdragon@mit.edu>\r
50 \r
51 Previously, we updated the database copy of a message on every call to\r
52 _notmuch_message_sync, even if nothing had changed.  In particular,\r
53 this always happens on a thaw, so a freeze/thaw pair with no\r
54 modifications between still caused a database update.\r
55 \r
56 We only modify message documents in a handful of places, so keep track\r
57 of whether the document has been modified and only sync it when\r
58 necessary.  This will be particularly important when we add message\r
59 revision tracking.\r
60 ---\r
61  lib/message.cc | 12 ++++++++++++\r
62  1 file changed, 12 insertions(+)\r
63 \r
64 diff --git a/lib/message.cc b/lib/message.cc\r
65 index 5bc7aff..1ddce3c 100644\r
66 --- a/lib/message.cc\r
67 +++ b/lib/message.cc\r
68 @@ -43,6 +43,9 @@ struct visible _notmuch_message {\r
69       * if each flag has been initialized. */\r
70      unsigned long lazy_flags;\r
71  \r
72 +    /* Message document modified since last sync */\r
73 +    notmuch_bool_t modified;\r
74 +\r
75      Xapian::Document doc;\r
76      Xapian::termcount termpos;\r
77  };\r
78 @@ -539,6 +542,7 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)\r
79  \r
80         try {\r
81             message->doc.remove_term ((*i));\r
82 +           message->modified = TRUE;\r
83         } catch (const Xapian::InvalidArgumentError) {\r
84             /* Ignore failure to remove non-existent term. */\r
85         }\r
86 @@ -793,6 +797,7 @@ void\r
87  _notmuch_message_clear_data (notmuch_message_t *message)\r
88  {\r
89      message->doc.set_data ("");\r
90 +    message->modified = TRUE;\r
91  }\r
92  \r
93  static void\r
94 @@ -990,6 +995,7 @@ _notmuch_message_set_header_values (notmuch_message_t *message,\r
95                             Xapian::sortable_serialise (time_value));\r
96      message->doc.add_value (NOTMUCH_VALUE_FROM, from);\r
97      message->doc.add_value (NOTMUCH_VALUE_SUBJECT, subject);\r
98 +    message->modified = TRUE;\r
99  }\r
100  \r
101  /* Synchronize changes made to message->doc out into the database. */\r
102 @@ -1001,8 +1007,12 @@ _notmuch_message_sync (notmuch_message_t *message)\r
103      if (message->notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)\r
104         return;\r
105  \r
106 +    if (! message->modified)\r
107 +       return;\r
108 +\r
109      db = static_cast <Xapian::WritableDatabase *> (message->notmuch->xapian_db);\r
110      db->replace_document (message->doc_id, message->doc);\r
111 +    message->modified = FALSE;\r
112  }\r
113  \r
114  /* Delete a message document from the database. */\r
115 @@ -1077,6 +1087,7 @@ _notmuch_message_add_term (notmuch_message_t *message,\r
116         return NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG;\r
117  \r
118      message->doc.add_term (term, 0);\r
119 +    message->modified = TRUE;\r
120  \r
121      talloc_free (term);\r
122  \r
123 @@ -1145,6 +1156,7 @@ _notmuch_message_remove_term (notmuch_message_t *message,\r
124  \r
125      try {\r
126         message->doc.remove_term (term);\r
127 +       message->modified = TRUE;\r
128      } catch (const Xapian::InvalidArgumentError) {\r
129         /* We'll let the philosopher's try to wrestle with the\r
130          * question of whether failing to remove that which was not\r
131 -- \r
132 2.1.4\r
133 \r