1 Return-Path: <james@jameswestby.net>
\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 DB168431FC0
\r
6 for <notmuch@notmuchmail.org>; Fri, 18 Dec 2009 16:12:02 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 Received: from olra.theworths.org ([127.0.0.1])
\r
9 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
10 with ESMTP id gubYVN8FosCK for <notmuch@notmuchmail.org>;
\r
11 Fri, 18 Dec 2009 16:12:01 -0800 (PST)
\r
12 Received: from jameswestby.net (jameswestby.net [89.145.97.141])
\r
13 by olra.theworths.org (Postfix) with ESMTP id 68580431FBF
\r
14 for <notmuch@notmuchmail.org>; Fri, 18 Dec 2009 16:12:01 -0800 (PST)
\r
15 Received: from cpc4-aztw22-2-0-cust59.aztw.cable.virginmedia.com
\r
16 ([94.169.116.60] helo=flash)
\r
17 by jameswestby.net with esmtpa (Exim 4.69)
\r
18 (envelope-from <james@jameswestby.net>)
\r
19 id 1NLmvP-0006Ca-TL; Sat, 19 Dec 2009 00:12:00 +0000
\r
20 Received: by flash (Postfix, from userid 1000)
\r
21 id 7075C6E546A; Sat, 19 Dec 2009 00:11:54 +0000 (GMT)
\r
22 From: James Westby <jw+debian@jameswestby.net>
\r
23 To: notmuch@notmuchmail.org
\r
24 Date: Sat, 19 Dec 2009 00:11:48 +0000
\r
25 Message-Id: <1261181508-22222-1-git-send-email-jw+debian@jameswestby.net>
\r
26 X-Mailer: git-send-email 1.6.3.3
\r
27 In-Reply-To: <871virzzjy.fsf@yoom.home.cworth.org>
\r
28 References: <871virzzjy.fsf@yoom.home.cworth.org>
\r
29 Subject: [notmuch] [PATCH v2] Store the size of the file for each message
\r
30 X-BeenThere: notmuch@notmuchmail.org
\r
31 X-Mailman-Version: 2.1.12
\r
33 List-Id: "Use and development of the notmuch mail system."
\r
34 <notmuch.notmuchmail.org>
\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
36 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
38 List-Post: <mailto:notmuch@notmuchmail.org>
\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
42 X-List-Received-Date: Sat, 19 Dec 2009 00:12:03 -0000
\r
44 When indexing a message store the filesize along with it so that
\r
45 when we store all the filenames for a message-id we can know if
\r
46 any of them have different content cheaply.
\r
48 The value stored is defined to be the largest filesize of any
\r
49 of the files for that message.
\r
51 This changes the API for efficiency reasons. The size is often
\r
52 known to the caller, and so we save a second stat by asking them
\r
53 to provide it. If they don't know it they can pass -1 and the
\r
54 stat will be done for them.
\r
56 We store the filesize such that we can query a range. Thus it
\r
57 would be possible to query "filesize:0..100" if you somehow
\r
58 knew the raw message was less that 100 bytes.
\r
61 With new, improved, working, filesize:.. search.
\r
63 lib/database.cc | 7 +++++++
\r
64 lib/message.cc | 25 +++++++++++++++++++++++++
\r
65 lib/notmuch-private.h | 8 +++++++-
\r
66 lib/notmuch.h | 5 +++++
\r
67 notmuch-new.c | 2 +-
\r
68 5 files changed, 45 insertions(+), 2 deletions(-)
\r
70 diff --git a/lib/database.cc b/lib/database.cc
\r
71 index b6c4d07..d834d94 100644
\r
72 --- a/lib/database.cc
\r
73 +++ b/lib/database.cc
\r
74 @@ -463,6 +463,8 @@ notmuch_database_open (const char *path,
\r
78 + Xapian::NumberValueRangeProcessor *filesize_proc = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_FILESIZE,
\r
79 + "filesize:", true);
\r
81 if (asprintf (¬much_path, "%s/%s", path, ".notmuch") == -1) {
\r
82 notmuch_path = NULL;
\r
83 @@ -508,6 +510,7 @@ notmuch_database_open (const char *path,
\r
84 notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));
\r
85 notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);
\r
86 notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);
\r
87 + notmuch->query_parser->add_valuerangeprocessor (filesize_proc);
\r
89 for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {
\r
90 prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];
\r
91 @@ -889,6 +892,7 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
\r
93 notmuch_database_add_message (notmuch_database_t *notmuch,
\r
94 const char *filename,
\r
96 notmuch_message_t **message_ret)
\r
98 notmuch_message_file_t *message_file;
\r
99 @@ -992,6 +996,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
100 if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
\r
101 _notmuch_message_set_filename (message, filename);
\r
102 _notmuch_message_add_term (message, "type", "mail");
\r
103 + ret = _notmuch_message_set_filesize (message, filename, size);
\r
107 ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
109 diff --git a/lib/message.cc b/lib/message.cc
\r
110 index 49519f1..2bfc5ed 100644
\r
111 --- a/lib/message.cc
\r
112 +++ b/lib/message.cc
\r
113 @@ -426,6 +426,31 @@ _notmuch_message_set_filename (notmuch_message_t *message,
\r
114 message->doc.set_data (s);
\r
118 +_notmuch_message_set_filesize (notmuch_message_t *message,
\r
119 + const char *filename,
\r
120 + const off_t size)
\r
123 + off_t realsize = size;
\r
124 + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
126 + if (realsize < 0) {
\r
127 + if (stat (filename, &st)) {
\r
128 + ret = NOTMUCH_STATUS_FILE_ERROR;
\r
131 + realsize = st.st_size;
\r
135 + message->doc.add_value (NOTMUCH_VALUE_FILESIZE,
\r
136 + Xapian::sortable_serialise (realsize));
\r
143 notmuch_message_get_filename (notmuch_message_t *message)
\r
145 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
146 index 116f63d..1ba3055 100644
\r
147 --- a/lib/notmuch-private.h
\r
148 +++ b/lib/notmuch-private.h
\r
149 @@ -100,7 +100,8 @@ _internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);
\r
152 NOTMUCH_VALUE_TIMESTAMP = 0,
\r
153 - NOTMUCH_VALUE_MESSAGE_ID
\r
154 + NOTMUCH_VALUE_MESSAGE_ID,
\r
155 + NOTMUCH_VALUE_FILESIZE
\r
158 /* Xapian (with flint backend) complains if we provide a term longer
\r
159 @@ -193,6 +194,11 @@ void
\r
160 _notmuch_message_set_filename (notmuch_message_t *message,
\r
161 const char *filename);
\r
164 +_notmuch_message_set_filesize (notmuch_message_t *message,
\r
165 + const char *filename,
\r
166 + const off_t size);
\r
169 _notmuch_message_ensure_thread_id (notmuch_message_t *message);
\r
171 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
172 index 60834fb..5d0d224 100644
\r
173 --- a/lib/notmuch.h
\r
174 +++ b/lib/notmuch.h
\r
176 NOTMUCH_BEGIN_DECLS
\r
179 +#include <stdlib.h>
\r
183 @@ -241,6 +242,9 @@ notmuch_database_get_timestamp (notmuch_database_t *database,
\r
184 * notmuch database will reference the filename, and will not copy the
\r
185 * entire contents of the file.
\r
187 + * 'size' should be the number of bytes in the file, or -1 if you are
\r
190 * If 'message' is not NULL, then, on successful return '*message'
\r
191 * will be initialized to a message object that can be used for things
\r
192 * such as adding tags to the just-added message. The user should call
\r
193 @@ -265,6 +269,7 @@ notmuch_database_get_timestamp (notmuch_database_t *database,
\r
195 notmuch_database_add_message (notmuch_database_t *database,
\r
196 const char *filename,
\r
197 + const off_t size,
\r
198 notmuch_message_t **message);
\r
200 /* Find a message with the given message_id.
\r
201 diff --git a/notmuch-new.c b/notmuch-new.c
\r
202 index 9d20616..cea66c2 100644
\r
203 --- a/notmuch-new.c
\r
204 +++ b/notmuch-new.c
\r
205 @@ -235,7 +235,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
209 - status = notmuch_database_add_message (notmuch, next, &message);
\r
210 + status = notmuch_database_add_message (notmuch, next, st->st_size, &message);
\r
213 case NOTMUCH_STATUS_SUCCESS:
\r