From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B20EB633860 for ; Sat, 19 Sep 2015 02:03:46 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 06/12] nntp: speed up XHDR for the Message-ID case Date: Sat, 19 Sep 2015 02:03:34 +0000 Message-Id: <20150919020340.6484-7-e@80x24.org> In-Reply-To: <20150919020340.6484-1-e@80x24.org> References: <20150919020340.6484-1-e@80x24.org> List-Id: We can use our msgmap database to implement "XHDR Message-ID [range]" commands quickly. This helps immensely with slrnpull, which prefers XHDR to LISTGROUP for some reason... --- lib/PublicInbox/NNTP.pm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 8275ef0..47b03e0 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -505,9 +505,45 @@ sub long_response ($$$$) { undef; } +sub xhdr_message_id ($$) { # optimize XHDR Message-ID [range] for slrnpull. + my ($self, $range) = @_; + + my $mm = $self->{ng}->mm; + if (defined $range && $range =~ /\A<(.+)>\z/) { # Message-ID + my $n = $mm->num_for($range); + more($self, '221 Header follows'); + more($self, "<$range> <$range>") if defined $n; + '.'; + } else { # numeric range + $range = $self->{article} unless defined $range; + my $r = get_range($self, $range); + return $r unless ref $r; + my ($beg, $end) = @$r; + more($self, '221 Header follows'); + $self->long_response($beg, $end, sub { + my ($i) = @_; + my $mid = $mm->mid_for($$i); + more($self, "$$i <$mid>") if defined $mid; + }); + } +} + sub cmd_xhdr ($$;$) { my ($self, $header, $range) = @_; defined $self->{ng} or return '412 no news group currently selected'; + my $sub = $header; + $sub =~ tr/A-Z-/a-z_/; + $sub = eval { + no strict 'refs'; + $sub = *{'xhdr_'.$sub}{CODE}; + }; + return xhdr_slow($self, $header, $range) unless defined $sub; + $sub->($self, $range); +} + +sub xhdr_slow ($$$) { + my ($self, $header, $range) = @_; + if (defined $range && $range =~ /\A<(.+)>\z/) { # Message-ID my $r = $self->art_lookup($range, 2); return $r unless ref $r; -- EW