about summary refs log tree commit homepage
path: root/lib/PublicInbox/Inbox.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-11 10:13:00 +0000
committerEric Wong <e@80x24.org>2017-01-11 10:19:35 +0000
commit1975aeaebbbdd628849964de42e183d04240c4e0 (patch)
treede84d0fd7bc445486b9c1a6af61bb404ebc75772 /lib/PublicInbox/Inbox.pm
parent3fc59df0d633a17e0c5e43d633d12e8772c06ec3 (diff)
downloadpublic-inbox-1975aeaebbbdd628849964de42e183d04240c4e0.tar.gz
We may need to do this even more aggressively, since the
Xapian database does not always give the latest results.
This time, we'll do it without relying on weak references,
and instead check refcounts.
Diffstat (limited to 'lib/PublicInbox/Inbox.pm')
-rw-r--r--lib/PublicInbox/Inbox.pm22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 51ada0bc..a0d69f18 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -7,6 +7,7 @@ use strict;
 use warnings;
 use PublicInbox::Git;
 use PublicInbox::MID qw(mid2path);
+use Devel::Peek qw(SvREFCNT);
 
 my $cleanup_timer;
 eval {
@@ -18,10 +19,20 @@ eval {
 my $CLEANUP = {}; # string(inbox) -> inbox
 sub cleanup_task () {
         $cleanup_timer = undef;
-        delete $_->{git} for values %$CLEANUP;
+        for my $ibx (values %$CLEANUP) {
+                foreach my $f (qw(git mm search)) {
+                        delete $ibx->{$f} if SvREFCNT($ibx->{$f}) == 1;
+                }
+        }
         $CLEANUP = {};
 }
 
+sub _cleanup_later ($) {
+        my ($self) = @_;
+        $cleanup_timer ||= PublicInbox::EvCleanup::later(*cleanup_task);
+        $CLEANUP->{"$self"} = $self;
+}
+
 sub _set_uint ($$$) {
         my ($opts, $field, $default) = @_;
         my $val = $opts->{$field};
@@ -70,20 +81,23 @@ sub git {
         $self->{git} ||= eval {
                 my $g = PublicInbox::Git->new($self->{mainrepo});
                 $g->{-httpbackend_limiter} = $self->{-httpbackend_limiter};
-                $cleanup_timer ||= PublicInbox::EvCleanup::later(*cleanup_task);
-                $CLEANUP->{"$self"} = $self;
+                _cleanup_later($self);
                 $g;
         };
 }
 
 sub mm {
         my ($self) = @_;
-        $self->{mm} ||= eval { PublicInbox::Msgmap->new($self->{mainrepo}) };
+        $self->{mm} ||= eval {
+                _cleanup_later($self);
+                PublicInbox::Msgmap->new($self->{mainrepo});
+        };
 }
 
 sub search {
         my ($self) = @_;
         $self->{search} ||= eval {
+                _cleanup_later($self);
                 PublicInbox::Search->new($self->{mainrepo}, $self->{altid});
         };
 }