X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FInbox.pm;h=813ed997f1781ccc3791257f751124fdf5ee9021;hb=0b1de991a099b5e8b9a9e3e85b5eaaacc9362dbb;hp=d57e46d29b2785f5b358f125cdb8beda00e332ae;hpb=59fd8cf084c6a67d9801c888a183eb83b552692d;p=public-inbox.git diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index d57e46d2..813ed997 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -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 over)) { 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->{over} || $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; } @@ -146,12 +168,24 @@ sub mm { }; } -sub search { - my ($self) = @_; - $self->{search} ||= eval { +sub search ($;$) { + my ($self, $over_only) = @_; + my $srch = $self->{search} ||= eval { _cleanup_later($self); + require PublicInbox::Search; PublicInbox::Search->new($self, $self->{altid}); }; + ($over_only || eval { $srch->xdb }) ? $srch : undef; +} + +sub over ($) { + my ($self) = @_; + my $srch = search($self, 1) or return; + $self->{over} ||= eval { + my $over = $srch->{over_ro}; + $over->dbh_new; # may fail + $over; + } } sub try_cat { @@ -189,8 +223,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} || '/'); @@ -258,8 +292,8 @@ sub nntp_url { sub nntp_usable { my ($self) = @_; - my $ret = $self->mm && $self->search; - $self->{mm} = $self->{search} = undef; + my $ret = mm($self) && over($self); + $self->{mm} = $self->{over} = $self->{search} = undef; $ret; } @@ -300,24 +334,38 @@ sub mid2num($$) { sub smsg_by_mid ($$) { my ($self, $mid) = @_; - my $srch = search($self) or return; + my $over = over($self) or return; # favor the Message-ID we used for the NNTP article number: defined(my $num = mid2num($self, $mid)) or return; - my $smsg = $srch->lookup_article($num) or return; + my $smsg = $over->get_art($num) or return; PublicInbox::SearchMsg::psgi_cull($smsg); } sub msg_by_mid ($$;$) { my ($self, $mid, $ref) = @_; - my $srch = search($self) or + + over($self) or return msg_by_path($self, mid2path($mid), $ref); + my $smsg = smsg_by_mid($self, $mid); $smsg ? msg_by_smsg($self, $smsg, $ref) : undef; } sub recent { my ($self, $opts, $after, $before) = @_; - search($self)->{over_ro}->recent($opts, $after, $before); + over($self)->recent($opts, $after, $before); +} + +sub modified { + my ($self) = @_; + if (my $over = over($self)) { + my $msgs = $over->recent({limit => 1}); + if (my $smsg = $msgs->[0]) { + return $smsg->{ts}; + } + return time; + } + git($self)->modified; # v1 } 1;