]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Inbox.pm
Merge remote-tracking branch 'origin/purge'
[public-inbox.git] / lib / PublicInbox / Inbox.pm
index d57e46d29b2785f5b358f125cdb8beda00e332ae..cde46258d02d630135f4efb12ba7b3d94178462e 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 ($) {
@@ -189,8 +202,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} || '/');