[PATCH v2 00/14] reply refactor, fixes
[notmuch-archives.git] / 50 / c1d3b65cedca67accd73659a1d30ab3005287d
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 CC891431FC2\r
6         for <notmuch@notmuchmail.org>; Thu, 24 Oct 2013 14:39:18 -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 R3cJTEIAWxAz for <notmuch@notmuchmail.org>;\r
16         Thu, 24 Oct 2013 14:39:11 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (dmz-mailsec-scanner-2.mit.edu\r
18         [18.9.25.13])\r
19         by olra.theworths.org (Postfix) with ESMTP id 26FD1431FB6\r
20         for <notmuch@notmuchmail.org>; Thu, 24 Oct 2013 14:39:11 -0700 (PDT)\r
21 X-AuditID: 1209190d-b7f528e0000009b4-08-5269937ead0a\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 06.26.02484.E7399625; Thu, 24 Oct 2013 17:39:10 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id r9OLd825031538; \r
27         Thu, 24 Oct 2013 17:39:08 -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 r9OLd6qB010508\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Thu, 24 Oct 2013 17:39:07 -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 1VZScU-0003Gj-89; Thu, 24 Oct 2013 17:39:06 -0400\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v2] new: Don't scan unchanged directories with no\r
40         sub-directories\r
41 Date: Thu, 24 Oct 2013 17:38:59 -0400\r
42 Message-Id: <1382650739-12438-1-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.8.4.rc3\r
44 In-Reply-To: <20131024210837.GH20337@mit.edu>\r
45 References: <20131024210837.GH20337@mit.edu>\r
46 X-Brightmail-Tracker:\r
47  H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixCmqrFs3OTPIYPNZdYvrN2cyW3Tc3s3m\r
48         wOTxbNUtZo+PT2+xBDBFcdmkpOZklqUW6dslcGXM6q0uuCBU8ePMdPYGxvV8XYycHBICJhJb\r
49         53WyQ9hiEhfurWfrYuTiEBLYxyjxpfUHE4SzkVHi1OW3jBDOESaJpzunsEM4cxkldr3eyAjS\r
50         zyagIbFt/3IwW0RAWmLn3dmsIDazgKPEngPLWUBsYYFAidnHb4DVsAioSiy8PwWshlfAQaLn\r
51         0lY2iDuUJBae2gYW5xTQlTi07RATiC0koCNxo+kN4wRG/gWMDKsYZVNyq3RzEzNzilOTdYuT\r
52         E/PyUot0jfRyM0v0UlNKNzGCQ0mSdwfju4NKhxgFOBiVeHg1PqQHCbEmlhVX5h5ilORgUhLl\r
53         NZ6UGSTEl5SfUpmRWJwRX1Sak1p8iFGCg1lJhHeaHlCONyWxsiq1KB8mJc3BoiTOe5PDPkhI\r
54         ID2xJDU7NbUgtQgmK8PBoSTBGw8yVLAoNT21Ii0zpwQhzcTBCTKcB2h4FkgNb3FBYm5xZjpE\r
55         /hSjopQ47waQhABIIqM0D64XFuuvGMWBXhHmrQSp4gGmCbjuV0CDmYAGT1mSBjK4JBEhJdXA\r
56         KJlbWCsr83PiVstOn8wlwgvv9aa/W/uyUYBb9cuBh0dTtzFudSuwnBcgs2ubzd6F0SYsHGaJ\r
57         VmsVytnaDJt1nzp/fpFc6M5323NL0UKtogMWs/k8eI63cpxet3ypaXBr9e2TM51fCd46f8/y\r
58         mf6EMxcSlOdkJxktfKETz9Rh8WVpUo/d5G9LlFiKMxINtZiLihMBqPKXbNACAAA=\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Thu, 24 Oct 2013 21:39:18 -0000\r
72 \r
73 This can substantially reduce the cost of notmuch new in some\r
74 situations, such as when the file system cache is cold or when the\r
75 Maildir is on NFS.\r
76 ---\r
77 \r
78 This should fix the problem with directories containing symlinks to\r
79 other directories, but no actual sub-directories.\r
80 \r
81  notmuch-new.c | 29 +++++++++++++++++++++++++++++\r
82  1 file changed, 29 insertions(+)\r
83 \r
84 diff --git a/notmuch-new.c b/notmuch-new.c\r
85 index faa33f1..ba05cb4 100644\r
86 --- a/notmuch-new.c\r
87 +++ b/notmuch-new.c\r
88 @@ -323,6 +323,35 @@ add_files (notmuch_database_t *notmuch,\r
89      }\r
90      db_mtime = directory ? notmuch_directory_get_mtime (directory) : 0;\r
91  \r
92 +    /* If the directory is unchanged from our last scan and has no\r
93 +     * sub-directories, then return without scanning it at all.  In\r
94 +     * some situations, skipping the scan can substantially reduce the\r
95 +     * cost of notmuch new, especially since the huge numbers of files\r
96 +     * in Maildirs make scans expensive, but all files live in leaf\r
97 +     * directories.\r
98 +     *\r
99 +     * To check for sub-directories, we borrow a trick from find,\r
100 +     * kpathsea, and many other UNIX tools: since a directory's link\r
101 +     * count is the number of sub-directories (specifically, their\r
102 +     * '..' entries) plus 2 (the link from the parent and the link for\r
103 +     * '.').  This check is safe even on weird file systems, since\r
104 +     * file systems that can't compute this will return 0 or 1.  This\r
105 +     * is safe even on *really* weird file systems like HFS+ that\r
106 +     * mistakenly return the total number of directory entries, since\r
107 +     * that only inflates the count beyond 2.\r
108 +     */\r
109 +    if (directory && fs_mtime == db_mtime && st.st_nlink == 2) {\r
110 +       /* There's one catch: pass 1 below considers symlinks to\r
111 +        * directories to be directories, but these don't increase the\r
112 +        * file system link count.  So, only bail early if the\r
113 +        * database agrees that there are no sub-directories. */\r
114 +       db_subdirs = notmuch_directory_get_child_directories (directory);\r
115 +       if (!notmuch_filenames_valid (db_subdirs))\r
116 +           goto DONE;\r
117 +       notmuch_filenames_destroy (db_subdirs);\r
118 +       db_subdirs = NULL;\r
119 +    }\r
120 +\r
121      /* If the database knows about this directory, then we sort based\r
122       * on strcmp to match the database sorting. Otherwise, we can do\r
123       * inode-based sorting for faster filesystem operation. */\r
124 -- \r
125 1.8.4.rc3\r
126 \r