From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 4D1FC1FEB3; Wed, 11 Jan 2017 10:21:04 +0000 (UTC) Date: Wed, 11 Jan 2017 10:21:04 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 11/9] inbox: reinstate periodic cleanup of Xapian and SQLite objects Message-ID: <20170111102104.GA12206@dcvr> References: <20170107014452.9657-1-e@80x24.org> <20170107014452.9657-6-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170107014452.9657-6-e@80x24.org> List-Id: 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 | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 51ada0b..a0d69f1 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}); }; } -- EW