]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www_stream: use DESTROY to cleanup temporary gits
authorEric Wong <e@80x24.org>
Sat, 1 Oct 2022 18:52:50 +0000 (15:52 -0300)
committerEric Wong <e@80x24.org>
Sat, 1 Oct 2022 23:02:18 +0000 (23:02 +0000)
Relying on a timer to handle cleanup in f9ac22a4b485 was
sub-optimal since the delay could prove expensive under heavy
traffic.  So rely on ->DESTROY instead since we we no longer
hold reference cycles by the time the show_blob callback
executes.

Fixes: f9ac22a4b485 ("git_async_cat: automatically cleanup temporary gits")
lib/PublicInbox/GitAsyncCat.pm
lib/PublicInbox/ViewVCS.pm
lib/PublicInbox/WwwStream.pm

index 2d601542964224de7c1d4fc630eda40929e50386..b32c2fd3cab4b6c665df483378b01f42952102c6 100644 (file)
@@ -45,12 +45,6 @@ sub event_step {
        }
 }
 
-sub git_tmp_cleanup {
-       my ($git) = @_;
-       $git->cleanup(1) and
-               PublicInbox::DS::add_timer(3, \&git_tmp_cleanup, $git);
-}
-
 sub ibx_async_cat ($$$$) {
        my ($ibx, $oid, $cb, $arg) = @_;
        my $git = $ibx->{git} // $ibx->git;
@@ -69,8 +63,6 @@ sub ibx_async_cat ($$$$) {
                $git->{async_cat} //= do {
                        my $self = bless { git => $git }, __PACKAGE__;
                        $git->{in}->blocking(0);
-                       $git->{-tmp} and PublicInbox::DS::add_uniq_timer(
-                                               3, \&git_tmp_cleanup, $git);
                        $self->SUPER::new($git->{in}, EPOLLIN|EPOLLET);
                        \undef; # this is a true ref()
                };
index 915cf2c5debe9e730ccc7bcd5329bc1bd11aefc9..b0f58455018b0ea03d97ddd42a377cccd927fd82 100644 (file)
@@ -414,6 +414,7 @@ blob $oid $size bytes $raw_link</pre>
 EOM
        }
        @{$ctx->{-paths}} = ($path, $raw_link);
+       bless $ctx, 'PublicInbox::WwwStream'; # for DESTROY
        $ctx->{git} = $git;
        if ($ctx->{env}->{'pi-httpd.async'}) {
                ibx_async_cat($ctx, $oid, \&show_blob, $ctx);
index 77b6f9c29e4ec675120cd2b47f5c6f003abb8e2f..16442d51a75fc1cac0b26332fbe9a8fad49d3e2b 100644 (file)
@@ -220,4 +220,9 @@ sub html_init {
        print { $ctx->zfh } html_top($ctx);
 }
 
+sub DESTROY {
+       my ($ctx) = @_;
+       $ctx->{git}->cleanup if $ctx->{git} && $ctx->{git}->{-tmp};
+}
+
 1;