about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-09-21 11:11:09 +0000
committerEric Wong <e@80x24.org>2015-09-21 11:37:03 +0000
commitf9d88ea6c375f6f265da1a13025abcc9e38d6839 (patch)
treedfc549c5b415047bbc736d0d51c13c2dd248e6b6 /lib
parente2c72e2671d395cbc3fff9cad5c8da4e08367e26 (diff)
downloadpublic-inbox-f9d88ea6c375f6f265da1a13025abcc9e38d6839.tar.gz
Reserializing the message to a string to check size wastes
considerable time and should be able to get by with slightly
less accuracy.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/GitCatFile.pm3
-rw-r--r--lib/PublicInbox/NNTP.pm5
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm
index 4f16762e..dd3f2912 100644
--- a/lib/PublicInbox/GitCatFile.pm
+++ b/lib/PublicInbox/GitCatFile.pm
@@ -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 = '';
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index d5eb4971..fb93330b 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -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('');
                 }
         }