From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C579420248; Thu, 18 Apr 2019 00:58:06 +0000 (UTC) Date: Thu, 18 Apr 2019 00:58:06 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH v3] inbox: add `modified' sub Message-ID: <20190418005806.64ceewey2hprujop@dcvr> References: <20190417114358.ab2hsmzo7eeehghs@dcvr> <20190417193506.6gradvjye5jvxeu5@dcvr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190417193506.6gradvjye5jvxeu5@dcvr> List-Id: For inboxes with SQLite enabled (all v2, and probably most v1); stat-ing the msgmap.sqlite3 file is a much faster way of telling when an inbox is modified compared to scanning git branches. v2: use mtime instead of ctime for users who use generic tools to copy SQLite DBs. v3: avoid uninitialized field for v1 repos (and I'm not sure why I used the "->{version} || 1" idiom everywhere instead of unconditionally setting it in Inbox->new...) --- lib/PublicInbox/Inbox.pm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index cde4625..ba3d2c7 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -333,4 +333,20 @@ sub recent { search($self)->{over_ro}->recent($opts, $after, $before); } +sub modified { + my ($self) = @_; + my $dir = $self->{mainrepo}; + my @st; + if (($self->{version} || 1) >= 2) { + @st = stat("$dir/msgmap.sqlite3") + } elsif (-f "$dir/public-inbox/msgmap.sqlite3") { # v1 + @st = stat(_); + } else { # v1 repos did not need sqlite3 + return git($self)->modified; + } + # we favor 9/mtime over ctime since it should be possible to + # use generic tools such as atomic-rsync to copy SQLite DBs + @st ? $st[9] : time; +} + 1; -- EW