]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Inbox.pm
www: support listing of inboxes
[public-inbox.git] / lib / PublicInbox / Inbox.pm
index 73f5761a875b1d1e6b8f6bfa3512248f6db54b5f..286555f65cb3b4c8f4a7820b0489e4f6f6005e72 100644 (file)
@@ -22,12 +22,25 @@ my $cleanup_broken = $@;
 my $CLEANUP = {}; # string(inbox) -> inbox
 sub cleanup_task () {
        $cleanup_timer = undef;
+       my $next = {};
        for my $ibx (values %$CLEANUP) {
-               foreach my $f (qw(git mm search)) {
+               my $again;
+               foreach my $f (qw(mm search)) {
                        delete $ibx->{$f} if SvREFCNT($ibx->{$f}) == 1;
                }
+               my $expire = time - 60;
+               if (my $git = $ibx->{git}) {
+                       $again = $git->cleanup($expire);
+               }
+               if (my $gits = $ibx->{-repo_objs}) {
+                       foreach my $git (@$gits) {
+                               $again = 1 if $git->cleanup($expire);
+                       }
+               }
+               $again ||= !!($ibx->{mm} || $ibx->{search});
+               $next->{"$ibx"} = $ibx if $again;
        }
-       $CLEANUP = {};
+       $CLEANUP = $next;
 }
 
 sub _cleanup_later ($) {
@@ -82,6 +95,15 @@ sub new {
        if (defined $dir && -f "$dir/inbox.lock") {
                $opts->{version} = 2;
        }
+
+       # allow any combination of multi-line or comma-delimited hide entries
+       my $hide = {};
+       if (defined(my $h = $opts->{hide})) {
+               foreach my $v (@$h) {
+                       $hide->{$_} = 1 foreach (split(/\s*,\s*/, $v));
+               }
+               $opts->{-hide} = $hide;
+       }
        bless $opts, $class;
 }
 
@@ -189,8 +211,8 @@ sub cloneurl {
 
 sub base_url {
        my ($self, $env) = @_;
-       if ($env) { # PSGI env
-               my $scheme = $env->{'psgi.url_scheme'};
+       my $scheme;
+       if ($env && ($scheme = $env->{'psgi.url_scheme'})) { # PSGI env
                my $host_port = $env->{HTTP_HOST} ||
                        "$env->{SERVER_NAME}:$env->{SERVER_PORT}";
                my $url = "$scheme://$host_port". ($env->{SCRIPT_NAME} || '/');
@@ -302,8 +324,9 @@ sub smsg_by_mid ($$) {
        my ($self, $mid) = @_;
        my $srch = search($self) or return;
        # favor the Message-ID we used for the NNTP article number:
-       my $num = mid2num($self, $mid);
-       defined $num ? $srch->lookup_article($num) : undef;
+       defined(my $num = mid2num($self, $mid)) or return;
+       my $smsg = $srch->lookup_article($num) or return;
+       PublicInbox::SearchMsg::psgi_cull($smsg);
 }
 
 sub msg_by_mid ($$;$) {
@@ -319,4 +342,16 @@ sub recent {
        search($self)->{over_ro}->recent($opts, $after, $before);
 }
 
+sub modified {
+       my ($self) = @_;
+       if (my $srch = search($self)) {
+               my $msgs = $srch->{over_ro}->recent({limit => 1});
+               if (my $smsg = $msgs->[0]) {
+                       return $smsg->{ts};
+               }
+               return time;
+       }
+       git($self)->modified; # v1
+}
+
 1;