about summary refs log tree commit homepage
path: root/lib/PublicInbox/Inbox.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-02-09 00:43:02 +0000
committerEric Wong <e@80x24.org>2017-02-09 00:43:02 +0000
commitfb9ed5324ec7de9420956840ba9a6585b81e8231 (patch)
treeab6b34f8459a585205a25d1f3d18d31437b89052 /lib/PublicInbox/Inbox.pm
parent1ab8dabe04ebba61fd8761dca3d569947cbe20be (diff)
parentba4c50c20b95679580beba1ef290a4281d5285b7 (diff)
downloadpublic-inbox-fb9ed5324ec7de9420956840ba9a6585b81e8231.tar.gz
* origin/master:
  config: do not slurp lines into memory
  TODO: several updates
  search: schema version bump for empty References/In-Reply-To
  Revert "searchidx: reindex clobbers old thread IDs"
  searchidx: reindex clobbers old thread IDs
  searchidx: deal with empty In-Reply-To and References headers
  searchview: increase limit for displaying search results
  searchview: clarify numeric summary at bottom
  add filter for Subject: tags
  watchmaildir: allow arguments for filters
  watchmaildir: limit live importer processes
  learn: implement "rm" only functionality
  mime: avoid SUPER usage in Email::MIME subclass
  inbox: reinstate periodic cleanup of Xapian and SQLite objects
  introduce PublicInbox::MIME wrapper class
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 1a844e1c..999f813b 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});
         };
 }