]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntp: speed up xover slightly
authorEric Wong <e@80x24.org>
Mon, 21 Sep 2015 11:11:09 +0000 (11:11 +0000)
committerEric Wong <e@80x24.org>
Mon, 21 Sep 2015 11:37:03 +0000 (11:37 +0000)
Reserializing the message to a string to check size wastes
considerable time and should be able to get by with slightly
less accuracy.

lib/PublicInbox/GitCatFile.pm
lib/PublicInbox/NNTP.pm

index 4f16762e56c8959eaaed4c7d91d3a7e647f7e729..dd3f2912cc2715d6a9ffd8449b2adce883db48a6 100644 (file)
@@ -38,7 +38,7 @@ sub _cat_file_begin {
 }
 
 sub cat_file {
-       my ($self, $object) = @_;
+       my ($self, $object, $sizeref) = @_;
 
        $object .= "\n";
        my $len = bytes::length($object);
@@ -58,6 +58,7 @@ sub cat_file {
                die "Unexpected result from git cat-file: $head\n";
 
        my $size = $1;
+       $$sizeref = $size if $sizeref;
        my $bytes_left = $size;
        my $offset = 0;
        my $rv = '';
index d5eb4971b845568fa8fbbe8482eff2201889f202..fb93330b43aaffa18374def94d77935acf2f9ccc 100644 (file)
@@ -366,7 +366,8 @@ find_mid:
        }
 found:
        my $o = 'HEAD:' . mid2path($mid);
-       my $s = eval { Email::Simple->new($ng->gcf->cat_file($o)) };
+       my $bytes;
+       my $s = eval { Email::Simple->new($ng->gcf->cat_file($o, \$bytes)) };
        return $err unless $s;
        if ($set_headers) {
                $s->header_set('Newsgroups', $ng->{name});
@@ -375,7 +376,7 @@ found:
 
                # must be last
                if ($set_headers == 2) {
-                       $s->header_set('Bytes', bytes::length($s->as_string));
+                       $s->header_set('Bytes', $bytes);
                        $s->body_set('');
                }
        }