Re: Filesystem functionality used by notmuch
[notmuch-archives.git] / 6d / b9fb36046010c6fbd2764c51f456d14fb45816
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 EC2F9431FBD\r
6         for <notmuch@notmuchmail.org>; Thu, 24 Oct 2013 13:33:54 -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: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 252tNtMlqSzj for <notmuch@notmuchmail.org>;\r
16         Thu, 24 Oct 2013 13:33:48 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (dmz-mailsec-scanner-4.mit.edu\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id A28E8431FBC\r
20         for <notmuch@notmuchmail.org>; Thu, 24 Oct 2013 13:33:48 -0700 (PDT)\r
21 X-AuditID: 1209190f-b7fa08e0000009c6-5d-5269842c51d6\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 40.D7.02502.C2489625; Thu, 24 Oct 2013 16:33:48 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id r9OKXjG9030310; \r
27         Thu, 24 Oct 2013 16:33:46 -0400\r
28 Received: from drake.dyndns.org (26-4-172.dynamic.csail.mit.edu [18.26.4.172])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r9OKXhnO016620\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Thu, 24 Oct 2013 16:33:45 -0400\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1VZRbD-0006Oz-U8; Thu, 24 Oct 2013 16:33:43 -0400\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH] new: Don't scan unchanged directories with no sub-directories\r
40 Date: Thu, 24 Oct 2013 16:33:42 -0400\r
41 Message-Id: <1382646822-24556-1-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.8.4.rc3\r
43 X-Brightmail-Tracker:\r
44  H4sIAAAAAAAAA+NgFlrMIsWRmVeSWpSXmKPExsUixG6nrqvTkhlkMH87p8X1mzOZLTpu72Zz\r
45         YPJ4tuoWs8fHp7dYApiiuGxSUnMyy1KL9O0SuDKafzxjLZjKV9Fy/B9bA+Ndri5GTg4JAROJ\r
46         x23zWCBsMYkL99azgdhCAvsYJbYfcuti5AKyNzJK7Pj/kB0icYRJ4tgzJ4jEXEaJT62LwbrZ\r
47         BDQktu1fzghiiwhIS+y8O5sVxGYWcJTYc2A5WI2wgJ/E/SkrgeIcHCwCqhJX5vCBhHkFHCSu\r
48         tR5kgzhCSWLhqW2sExh5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdI10cvNLNFLTSndxAgK\r
49         C05J/h2M3w4qHWIU4GBU4uHV+JAeJMSaWFZcmXuIUZKDSUmUd11TZpAQX1J+SmVGYnFGfFFp\r
50         TmrxIUYJDmYlEd5pekA53pTEyqrUonyYlDQHi5I4700O+yAhgfTEktTs1NSC1CKYrAwHh5IE\r
51         7w2QoYJFqempFWmZOSUIaSYOTpDhPEDDn4HU8BYXJOYWZ6ZD5E8xKkqJ8/4ESQiAJDJK8+B6\r
52         YXH7ilEc6BVh3n8gVTzAmIfrfgU0mAlo8JQlaSCDSxIRUlINjIHzNLe++KZvH3f4ssqzHxt2\r
53         CO0puR7aKJWqaqcruuPxpV4uA40E/tuvGbZbFt2cdnC9y+2FD3ojSoVWTHMr0zw6f3NB1sTO\r
54         RaGMLIs7TvUJGIsen1e6Ivv+v30f1dK4M87pzuY/YsAUzidVsYlvnmyEk37hkZJpExQcu39a\r
55         zuyWqf2xrjLtoxJLcUaioRZzUXEiAB53vU+2AgAA\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Thu, 24 Oct 2013 20:33:55 -0000\r
69 \r
70 This can substantially reduce the cost of notmuch new in some\r
71 situations, such as when the file system cache is cold or when the\r
72 Maildir is on NFS.\r
73 ---\r
74  notmuch-new.c | 20 ++++++++++++++++++++\r
75  1 file changed, 20 insertions(+)\r
76 \r
77 diff --git a/notmuch-new.c b/notmuch-new.c\r
78 index faa33f1..364c73a 100644\r
79 --- a/notmuch-new.c\r
80 +++ b/notmuch-new.c\r
81 @@ -323,6 +323,26 @@ add_files (notmuch_database_t *notmuch,\r
82      }\r
83      db_mtime = directory ? notmuch_directory_get_mtime (directory) : 0;\r
84  \r
85 +    /* If the directory is unchanged from our last scan and has no\r
86 +     * sub-directories, then return without scanning it at all.  In\r
87 +     * some situations, skipping the scan can substantially reduce the\r
88 +     * cost of notmuch new, especially since the huge numbers of files\r
89 +     * in Maildirs make scans expensive, but all files live in leaf\r
90 +     * directories.\r
91 +     *\r
92 +     * To check for sub-directories, we borrow a trick from find,\r
93 +     * kpathsea, and many other UNIX tools: since a directory's link\r
94 +     * count is the number of sub-directories (specifically, their\r
95 +     * '..' entries) plus 2 (the link from the parent and the link for\r
96 +     * '.').  This check is safe even on weird file systems, since\r
97 +     * file systems that can't compute this will return 0 or 1.  This\r
98 +     * is safe even on *really* weird file systems like HFS+ that\r
99 +     * mistakenly return the total number of directory entries, since\r
100 +     * that only inflates the count beyond 2.\r
101 +     */\r
102 +    if (directory && fs_mtime == db_mtime && st.st_nlink == 2)\r
103 +       goto DONE;\r
104 +\r
105      /* If the database knows about this directory, then we sort based\r
106       * on strcmp to match the database sorting. Otherwise, we can do\r
107       * inode-based sorting for faster filesystem operation. */\r
108 -- \r
109 1.8.4.rc3\r
110 \r