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 4F5CD431FBF
\r
6 for <notmuch@notmuchmail.org>; Fri, 18 Dec 2009 13:21:50 -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 wggElni5n0rm for <notmuch@notmuchmail.org>;
\r
11 Fri, 18 Dec 2009 13:21:49 -0800 (PST)
\r
12 Received: from jameswestby.net (jameswestby.net [89.145.97.141])
\r
13 by olra.theworths.org (Postfix) with ESMTP id B7959431FAE
\r
14 for <notmuch@notmuchmail.org>; Fri, 18 Dec 2009 13:21:48 -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 1NLkGh-0005zF-CJ; Fri, 18 Dec 2009 21:21:47 +0000
\r
20 Received: by flash (Postfix, from userid 1000)
\r
21 id E1A276E546A; Fri, 18 Dec 2009 21:21:41 +0000 (GMT)
\r
22 From: James Westby <jw+debian@jameswestby.net>
\r
23 To: notmuch@notmuchmail.org
\r
24 Date: Fri, 18 Dec 2009 21:21:03 +0000
\r
25 Message-Id: <1261171263-29687-1-git-send-email-jw+debian@jameswestby.net>
\r
26 X-Mailer: git-send-email 1.6.3.3
\r
27 In-Reply-To: <87my1grrdi.fsf@jameswestby.net>
\r
28 References: <87my1grrdi.fsf@jameswestby.net>
\r
29 Subject: [notmuch] [PATCH] 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: Fri, 18 Dec 2009 21:21:50 -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 Here's the first part, storing the filesize. I'm using
\r
62 add_value so that we can make it sortable, is that valid
\r
63 for retrieving it as well?
\r
65 The only thing I'm not sure about is if it works. Is there
\r
66 a way to inspect a document to see the values that are
\r
67 stored? Doing a search isn't working, so I imagine I made
\r
74 lib/database.cc | 17 +++++++++++++++++
\r
75 lib/message.cc | 25 +++++++++++++++++++++++++
\r
76 lib/notmuch-private.h | 8 +++++++-
\r
77 lib/notmuch.h | 5 +++++
\r
78 notmuch-new.c | 2 +-
\r
79 5 files changed, 55 insertions(+), 2 deletions(-)
\r
81 diff --git a/lib/database.cc b/lib/database.cc
\r
82 index b6c4d07..0ec77cd 100644
\r
83 --- a/lib/database.cc
\r
84 +++ b/lib/database.cc
\r
85 @@ -454,6 +454,17 @@ notmuch_database_create (const char *path)
\r
89 +struct FilesizeValueRangeProcessor : public Xapian::ValueRangeProcessor {
\r
90 + FilesizeValueRangeProcessor() {}
\r
92 + Xapian::valueno operator()(std::string &begin, std::string &) {
\r
93 + if (begin.substr(0, 9) != "filesize:")
\r
94 + return Xapian::BAD_VALUENO;
\r
95 + begin.erase(0, 9);
\r
96 + return NOTMUCH_VALUE_FILESIZE;
\r
100 notmuch_database_t *
\r
101 notmuch_database_open (const char *path,
\r
102 notmuch_database_mode_t mode)
\r
103 @@ -463,6 +474,7 @@ notmuch_database_open (const char *path,
\r
107 + FilesizeValueRangeProcessor filesize_proc;
\r
109 if (asprintf (¬much_path, "%s/%s", path, ".notmuch") == -1) {
\r
110 notmuch_path = NULL;
\r
111 @@ -508,6 +520,7 @@ notmuch_database_open (const char *path,
\r
112 notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));
\r
113 notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);
\r
114 notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);
\r
115 + notmuch->query_parser->add_valuerangeprocessor (&filesize_proc);
\r
117 for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {
\r
118 prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];
\r
119 @@ -889,6 +902,7 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
\r
121 notmuch_database_add_message (notmuch_database_t *notmuch,
\r
122 const char *filename,
\r
123 + const off_t size,
\r
124 notmuch_message_t **message_ret)
\r
126 notmuch_message_file_t *message_file;
\r
127 @@ -992,6 +1006,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
128 if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
\r
129 _notmuch_message_set_filename (message, filename);
\r
130 _notmuch_message_add_term (message, "type", "mail");
\r
131 + ret = _notmuch_message_set_filesize (message, filename, size);
\r
135 ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
137 diff --git a/lib/message.cc b/lib/message.cc
\r
138 index 49519f1..2bfc5ed 100644
\r
139 --- a/lib/message.cc
\r
140 +++ b/lib/message.cc
\r
141 @@ -426,6 +426,31 @@ _notmuch_message_set_filename (notmuch_message_t *message,
\r
142 message->doc.set_data (s);
\r
146 +_notmuch_message_set_filesize (notmuch_message_t *message,
\r
147 + const char *filename,
\r
148 + const off_t size)
\r
151 + off_t realsize = size;
\r
152 + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
154 + if (realsize < 0) {
\r
155 + if (stat (filename, &st)) {
\r
156 + ret = NOTMUCH_STATUS_FILE_ERROR;
\r
159 + realsize = st.st_size;
\r
163 + message->doc.add_value (NOTMUCH_VALUE_FILESIZE,
\r
164 + Xapian::sortable_serialise (realsize));
\r
171 notmuch_message_get_filename (notmuch_message_t *message)
\r
173 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
174 index 116f63d..1ba3055 100644
\r
175 --- a/lib/notmuch-private.h
\r
176 +++ b/lib/notmuch-private.h
\r
177 @@ -100,7 +100,8 @@ _internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);
\r
180 NOTMUCH_VALUE_TIMESTAMP = 0,
\r
181 - NOTMUCH_VALUE_MESSAGE_ID
\r
182 + NOTMUCH_VALUE_MESSAGE_ID,
\r
183 + NOTMUCH_VALUE_FILESIZE
\r
186 /* Xapian (with flint backend) complains if we provide a term longer
\r
187 @@ -193,6 +194,11 @@ void
\r
188 _notmuch_message_set_filename (notmuch_message_t *message,
\r
189 const char *filename);
\r
192 +_notmuch_message_set_filesize (notmuch_message_t *message,
\r
193 + const char *filename,
\r
194 + const off_t size);
\r
197 _notmuch_message_ensure_thread_id (notmuch_message_t *message);
\r
199 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
200 index 60834fb..5d0d224 100644
\r
201 --- a/lib/notmuch.h
\r
202 +++ b/lib/notmuch.h
\r
204 NOTMUCH_BEGIN_DECLS
\r
207 +#include <stdlib.h>
\r
211 @@ -241,6 +242,9 @@ notmuch_database_get_timestamp (notmuch_database_t *database,
\r
212 * notmuch database will reference the filename, and will not copy the
\r
213 * entire contents of the file.
\r
215 + * 'size' should be the number of bytes in the file, or -1 if you are
\r
218 * If 'message' is not NULL, then, on successful return '*message'
\r
219 * will be initialized to a message object that can be used for things
\r
220 * such as adding tags to the just-added message. The user should call
\r
221 @@ -265,6 +269,7 @@ notmuch_database_get_timestamp (notmuch_database_t *database,
\r
223 notmuch_database_add_message (notmuch_database_t *database,
\r
224 const char *filename,
\r
225 + const off_t size,
\r
226 notmuch_message_t **message);
\r
228 /* Find a message with the given message_id.
\r
229 diff --git a/notmuch-new.c b/notmuch-new.c
\r
230 index 9d20616..cea66c2 100644
\r
231 --- a/notmuch-new.c
\r
232 +++ b/notmuch-new.c
\r
233 @@ -235,7 +235,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
237 - status = notmuch_database_add_message (notmuch, next, &message);
\r
238 + status = notmuch_database_add_message (notmuch, next, st->st_size, &message);
\r
241 case NOTMUCH_STATUS_SUCCESS:
\r