From: Eric Wong Date: Wed, 11 Jan 2017 10:13:00 +0000 (+0000) Subject: inbox: reinstate periodic cleanup of Xapian and SQLite objects X-Git-Tag: v1.0.0~95 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=1975aeaebbbdd628849964de42e183d04240c4e0 inbox: reinstate periodic cleanup of Xapian and SQLite objects 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. --- 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}); }; }