Re: Filesystem functionality used by notmuch
[notmuch-archives.git] / 99 / 4553b5f37ab97fbe2ce781e95cc59c2293bac7
1 Return-Path: <amdragon@mit.edu>\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 olra.theworths.org (Postfix) with ESMTP id E5784431FDA\r
6         for <notmuch@notmuchmail.org>; Thu, 31 Jul 2014 19:10:24 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id vomXrPoGecHu for <notmuch@notmuchmail.org>;\r
16         Thu, 31 Jul 2014 19:10:19 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
18         [18.7.68.37])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id E6E5A431FBF\r
22         for <notmuch@notmuchmail.org>; Thu, 31 Jul 2014 19:10:11 -0700 (PDT)\r
23 X-AuditID: 12074425-f79766d000006da8-5f-53daf7020207\r
24 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
25         (using TLS with cipher AES256-SHA (256/256 bits))\r
26         (Client did not present a certificate)\r
27         by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
28         id BA.2B.28072.207FAD35; Thu, 31 Jul 2014 22:10:11 -0400 (EDT)\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
30         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id s712A8ll014705; \r
31         Thu, 31 Jul 2014 22:10:09 -0400\r
32 Received: from drake.dyndns.org\r
33         (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
34         [216.15.114.40]) (authenticated bits=0)\r
35         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
36         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s712A6qU029989\r
37         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
38         Thu, 31 Jul 2014 22:10:08 -0400\r
39 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
40         (envelope-from <amdragon@mit.edu>)\r
41         id 1XD2II-00033q-43; Thu, 31 Jul 2014 22:10:06 -0400\r
42 From: Austin Clements <amdragon@MIT.EDU>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH v3 09/13] lib: Reorganize upgrade around document types\r
45 Date: Thu, 31 Jul 2014 22:09:59 -0400\r
46 Message-Id: <1406859003-11561-10-git-send-email-amdragon@mit.edu>\r
47 X-Mailer: git-send-email 2.0.0\r
48 In-Reply-To: <1406859003-11561-1-git-send-email-amdragon@mit.edu>\r
49 References: <1406859003-11561-1-git-send-email-amdragon@mit.edu>\r
50 X-Brightmail-Tracker:\r
51  H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixCmqrMv8/VawwZcuJovVc3ksrt+cyezA\r
52         5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZczYMJG14KlCxc0jU5kbGL9KdjFyckgImEjM\r
53         3LOYBcIWk7hwbz1bFyMXh5DAbCaJUxsvskM4Gxkl3nXNYgOpEhK4wyTxdhNUYi6jxIt/zUwg\r
54         CTYBDYlt+5czgtgiAtISO+/OZgWxmQUcJT7vXwTWLCzgLjFxbzuYzSKgKjH17nuwGl6gmiWv\r
55         rkGdISfRcOMTWA0nUPz/vwWsEIsdJFpPb2WewMi/gJFhFaNsSm6Vbm5iZk5xarJucXJiXl5q\r
56         ka6FXm5miV5qSukmRlAgsbuo7mCccEjpEKMAB6MSD69D6K1gIdbEsuLK3EOMkhxMSqK8Nh+B\r
57         QnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4X34AyvGmJFZWpRblw6SkOViUxHnfWlsFCwmkJ5ak\r
58         ZqemFqQWwWRlODiUJHjPfAVqFCxKTU+tSMvMKUFIM3FwggznARou9A1keHFBYm5xZjpE/hSj\r
59         opQ47x6QZgGQREZpHlwvLNJfMYoDvSLM+xCkigeYJOC6XwENZgIa/PzWdZDBJYkIKakGxkmL\r
60         +A+Z79T0ZU/lm29eKB3zlm8PyxwDxb3OKrbrM7Y+XXlK6s6b0sWeRcKTDO8lbP7/i+GpyvH5\r
61         kpdrnrJ+s1bQyQiZZTDz8IU66zcpssUfa2oO9R6V3/mbJfaXwGOnCRnh7jmxuybsFIkUyauX\r
62         bL+od+N/erjv+iv8InO7ltW66cxR6+9UV2Ipzkg01GIuKk4EAGhvjO3PAgAA\r
63 X-BeenThere: notmuch@notmuchmail.org\r
64 X-Mailman-Version: 2.1.13\r
65 Precedence: list\r
66 List-Id: "Use and development of the notmuch mail system."\r
67         <notmuch.notmuchmail.org>\r
68 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
69         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
70 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
71 List-Post: <mailto:notmuch@notmuchmail.org>\r
72 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
73 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
74         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
75 X-List-Received-Date: Fri, 01 Aug 2014 02:10:25 -0000\r
76 \r
77 Rather than potentially making multiple passes over the same type of\r
78 data in the database, reorganize upgrade around each type of data that\r
79 may be upgraded.  This eliminates code duplication, will make\r
80 multi-version upgrades faster, and will let us improve progress\r
81 reporting.\r
82 ---\r
83  lib/database.cc | 72 +++++++++++++++++++++------------------------------------\r
84  1 file changed, 26 insertions(+), 46 deletions(-)\r
85 \r
86 diff --git a/lib/database.cc b/lib/database.cc\r
87 index 69d775f..31e6a93 100644\r
88 --- a/lib/database.cc\r
89 +++ b/lib/database.cc\r
90 @@ -1241,11 +1241,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
91       * format. */\r
92      notmuch->features = target_features;\r
93  \r
94 -    /* Before version 1, each message document had its filename in the\r
95 -     * data field. Copy that into the new format by calling\r
96 -     * notmuch_message_add_filename.\r
97 -     */\r
98 -    if (new_features & NOTMUCH_FEATURE_FILE_TERMS) {\r
99 +    /* Perform per-message upgrades. */\r
100 +    if (new_features &\r
101 +       (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {\r
102         notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
103         notmuch_messages_t *messages;\r
104         notmuch_message_t *message;\r
105 @@ -1264,13 +1262,27 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
106  \r
107             message = notmuch_messages_get (messages);\r
108  \r
109 -           filename = _notmuch_message_talloc_copy_data (message);\r
110 -           if (filename && *filename != '\0') {\r
111 -               _notmuch_message_add_filename (message, filename);\r
112 -               _notmuch_message_clear_data (message);\r
113 -               _notmuch_message_sync (message);\r
114 +           /* Before version 1, each message document had its\r
115 +            * filename in the data field. Copy that into the new\r
116 +            * format by calling notmuch_message_add_filename.\r
117 +            */\r
118 +           if (new_features & NOTMUCH_FEATURE_FILE_TERMS) {\r
119 +               filename = _notmuch_message_talloc_copy_data (message);\r
120 +               if (filename && *filename != '\0') {\r
121 +                   _notmuch_message_add_filename (message, filename);\r
122 +                   _notmuch_message_clear_data (message);\r
123 +               }\r
124 +               talloc_free (filename);\r
125             }\r
126 -           talloc_free (filename);\r
127 +\r
128 +           /* Prior to version 2, the "folder:" prefix was\r
129 +            * probabilistic and stemmed. Change it to the current\r
130 +            * boolean prefix. Add "path:" prefixes while at it.\r
131 +            */\r
132 +           if (new_features & NOTMUCH_FEATURE_BOOL_FOLDER)\r
133 +               _notmuch_message_upgrade_folder (message);\r
134 +\r
135 +           _notmuch_message_sync (message);\r
136  \r
137             notmuch_message_destroy (message);\r
138  \r
139 @@ -1280,7 +1292,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
140         notmuch_query_destroy (query);\r
141      }\r
142  \r
143 -    /* Also, before version 1 we stored directory timestamps in\r
144 +    /* Perform per-directory upgrades. */\r
145 +\r
146 +    /* Before version 1 we stored directory timestamps in\r
147       * XTIMESTAMP documents instead of the current XDIRECTORY\r
148       * documents. So copy those as well. */\r
149      if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {\r
150 @@ -1322,40 +1336,6 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
151         }\r
152      }\r
153  \r
154 -    /*\r
155 -     * Prior to version 2, the "folder:" prefix was probabilistic and\r
156 -     * stemmed. Change it to the current boolean prefix. Add "path:"\r
157 -     * prefixes while at it.\r
158 -     */\r
159 -    if (new_features & NOTMUCH_FEATURE_BOOL_FOLDER) {\r
160 -       notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
161 -       notmuch_messages_t *messages;\r
162 -       notmuch_message_t *message;\r
163 -\r
164 -       count = 0;\r
165 -       total = notmuch_query_count_messages (query);\r
166 -\r
167 -       for (messages = notmuch_query_search_messages (query);\r
168 -            notmuch_messages_valid (messages);\r
169 -            notmuch_messages_move_to_next (messages)) {\r
170 -           if (do_progress_notify) {\r
171 -               progress_notify (closure, (double) count / total);\r
172 -               do_progress_notify = 0;\r
173 -           }\r
174 -\r
175 -           message = notmuch_messages_get (messages);\r
176 -\r
177 -           _notmuch_message_upgrade_folder (message);\r
178 -           _notmuch_message_sync (message);\r
179 -\r
180 -           notmuch_message_destroy (message);\r
181 -\r
182 -           count++;\r
183 -       }\r
184 -\r
185 -       notmuch_query_destroy (query);\r
186 -    }\r
187 -\r
188      db->set_metadata ("features", _print_features (local, notmuch->features));\r
189      db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));\r
190  \r
191 -- \r
192 2.0.0\r
193 \r