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,AWL,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 592B620101 for ; Mon, 21 Sep 2015 11:11:15 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/6] nntp: speed up XHDR Xref for rtin Date: Mon, 21 Sep 2015 11:11:08 +0000 Message-Id: <20150921111112.18873-3-e@80x24.org> In-Reply-To: <20150921111112.18873-1-e@80x24.org> References: <20150921111112.18873-1-e@80x24.org> List-Id: We could also start displaying Xref in XOVER as rtin seems to prefer it. Anyways this is nearly 100 times faster now and requires no DB changes. --- lib/PublicInbox/NNTP.pm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 79f2c2f..d5eb497 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -371,7 +371,7 @@ found: if ($set_headers) { $s->header_set('Newsgroups', $ng->{name}); $s->header_set('Lines', $s->body =~ tr!\n!\n!); - $s->header_set('Xref', "$ng->{domain} $ng->{name}:$n"); + $s->header_set('Xref', xref($ng, $n)); # must be last if ($set_headers == 2) { @@ -562,6 +562,35 @@ sub xhdr_message_id ($$) { # optimize XHDR Message-ID [range] for slrnpull. } } +sub xref ($$) { + my ($ng, $n) = @_; + "$ng->{domain} $ng->{name}:$n" +} + +sub xhdr_xref ($$) { # optimize XHDR Xref [range] for rtin + my ($self, $range) = @_; + + my $ng = $self->{ng}; + my $mm = $ng->mm; + if (defined $range && $range =~ /\A<(.+)>\z/) { # Message-ID + my $n = $mm->num_for($range); + more($self, '221 Header follows'); + more($self, "<$range> ".xref($ng, $n)) 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 ".xref($ng, $$i)) if defined $mid; + }); + } +} + sub header_obj_for { my ($srch, $mid) = @_; eval { @@ -612,6 +641,8 @@ sub cmd_xhdr ($$;$) { my $sub = lc $header; if ($sub eq 'message-id') { xhdr_message_id($self, $range); + } elsif ($sub eq 'xref') { + xhdr_xref($self, $range); } elsif ($sub =~ /\A(subject|references|date)\z/ && $ng->search) { xhdr_searchmsg($self, $sub, $range); } else { -- EW