about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiOverview.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-31 22:28:16 -1000
committerEric Wong <e@80x24.org>2021-02-01 11:38:10 +0000
commit21ce1a28915374297829bd05feda0cea52adb324 (patch)
treef564e868b9e3396ca60e9c3897fbaa467cb8f3b2 /lib/PublicInbox/LeiOverview.pm
parentdbf555ee5906e5c778941ee850a88640a026b0ea (diff)
downloadpublic-inbox-21ce1a28915374297829bd05feda0cea52adb324.tar.gz
It doesn't save us any code, and the action-at-a-distance
element was making it confusing to track down actual problems.
Another potential problem was keeping references alive too long.

So do like we would a C100K server and check every write
while still ensuring lei(1) exit with a proper SIGPIPE
iff needed.
Diffstat (limited to 'lib/PublicInbox/LeiOverview.pm')
-rw-r--r--lib/PublicInbox/LeiOverview.pm33
1 files changed, 12 insertions, 21 deletions
diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm
index fa041457..1d62ffe2 100644
--- a/lib/PublicInbox/LeiOverview.pm
+++ b/lib/PublicInbox/LeiOverview.pm
@@ -107,28 +107,22 @@ sub new {
 sub ovv_begin {
         my ($self, $lei) = @_;
         if ($self->{fmt} eq 'json') {
-                print { $lei->{1} } '[';
+                $lei->out('[');
         } # TODO HTML/Atom/...
 }
 
 # called once by parent (via PublicInbox::EOFpipe)
 sub ovv_end {
         my ($self, $lei) = @_;
-        my $out = $lei->{1} or return;
         if ($self->{fmt} eq 'json') {
                 # JSON doesn't allow trailing commas, and preventing
                 # trailing commas is a PITA when parallelizing outputs
-                print $out "null]\n";
+                $lei->out("null]\n");
         } elsif ($self->{fmt} eq 'concatjson') {
-                print $out "\n";
+                $lei->out("\n");
         }
 }
 
-sub ovv_atfork_child {
-        my ($self) = @_;
-        # reopen dedupe here
-}
-
 # prepares an smsg for JSON
 sub _unbless_smsg {
         my ($smsg, $mitem) = @_;
@@ -168,9 +162,8 @@ sub ovv_atexit_child {
                 $git->async_wait_all;
         }
         if (my $bref = delete $lei->{ovv_buf}) {
-                my $out = $lei->{1} or return;
                 my $lk = $self->lock_for_scope;
-                print $out $$bref;
+                $lei->out($$bref);
         }
 }
 
@@ -268,11 +261,10 @@ sub ovv_each_smsg_cb { # runs in wq worker usually
                                 }
                         } sort keys %$smsg);
                         $buf .= $EOR;
-                        if (length($buf) > 65536) {
-                                my $lk = $self->lock_for_scope;
-                                print { $lei->{1} } $buf;
-                                $buf = '';
-                        }
+                        return if length($buf) < 65536;
+                        my $lk = $self->lock_for_scope;
+                        $lei->out($buf);
+                        $buf = '';
                 }
         } elsif ($json) {
                 my $ORS = $self->{fmt} eq 'json' ? ",\n" : "\n"; # JSONL
@@ -280,11 +272,10 @@ sub ovv_each_smsg_cb { # runs in wq worker usually
                         my ($smsg, $mitem) = @_;
                         return if $dedupe->is_smsg_dup($smsg);
                         $buf .= $json->encode(_unbless_smsg(@_)) . $ORS;
-                        if (length($buf) > 65536) {
-                                my $lk = $self->lock_for_scope;
-                                print { $lei->{1} } $buf;
-                                $buf = '';
-                        }
+                        return if length($buf) < 65536;
+                        my $lk = $self->lock_for_scope;
+                        $lei->out($buf);
+                        $buf = '';
                 }
         } # else { ...
 }