]> Sergey Matveev's repositories - public-inbox.git/commitdiff
inbox: reinstate periodic cleanup of Xapian and SQLite objects
authorEric Wong <e@80x24.org>
Wed, 11 Jan 2017 10:13:00 +0000 (10:13 +0000)
committerEric Wong <e@80x24.org>
Wed, 11 Jan 2017 10:19:35 +0000 (10:19 +0000)
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.

lib/PublicInbox/Inbox.pm

index 51ada0bc390458df9a992ff77ca934097293db60..a0d69f1813f92b1efa148ca35a7f85590bdbb236 100644 (file)
@@ -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});
        };
 }