user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/5] nntp: NEWGROUPS uses long_response
Date: Sat, 28 Nov 2020 05:09:12 +0000	[thread overview]
Message-ID: <20201128050916.5586-2-e@80x24.org> (raw)
In-Reply-To: <20201128050916.5586-1-e@80x24.org>

We can amortize the cost of NEWGROUPS time filtering using the
long_response API.  This lets us handle hundreds/thousands of
inboxes without monopolizing the event loop for this command.

Further speedup is possible using MiscSearch, but that requires
not-yet-done indexing changes to MiscIdx.
---
 lib/PublicInbox/NNTP.pm  | 21 +++++++++++++++------
 lib/PublicInbox/NNTPD.pm |  5 +----
 t/nntp.t                 |  1 -
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 8eec6b91..cc6534b9 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -263,6 +263,19 @@ sub group_line ($$) {
 	more($self, "$ng->{newsgroup} $max $min n");
 }
 
+sub newgroups_i {
+	my ($self, $ts, $i, $groupnames) = @_;
+	my $end = $$i + 100;
+	my $groups = $self->{nntpd}->{pi_config}->{-by_newsgroup};
+	while ($$i < $end) {
+		my $ngname = $groupnames->[$$i++] // return;
+		my $ibx = $groups->{$ngname} or next; # expired on reload
+		next unless (eval { $ibx->uidvalidity } // 0) > $ts;
+		group_line($self, $ibx);
+	}
+	1;
+}
+
 sub cmd_newgroups ($$$;$$) {
 	my ($self, $date, $time, $gmt, $dists) = @_;
 	my $ts = eval { parse_time($date, $time, $gmt) };
@@ -270,12 +283,8 @@ sub cmd_newgroups ($$$;$$) {
 
 	# TODO dists
 	more($self, '231 list of new newsgroups follows');
-	foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
-		my $c = eval { $ng->uidvalidity } // 0;
-		next unless $c > $ts;
-		group_line($self, $ng);
-	}
-	'.'
+	long_response($self, \&newgroups_i, $ts, \(my $i = 0),
+				$self->{nntpd}->{groupnames});
 }
 
 sub wildmat2re (;$) {
diff --git a/lib/PublicInbox/NNTPD.pm b/lib/PublicInbox/NNTPD.pm
index 4de1944b..33bc5fda 100644
--- a/lib/PublicInbox/NNTPD.pm
+++ b/lib/PublicInbox/NNTPD.pm
@@ -24,7 +24,6 @@ sub new {
 		groups => {},
 		err => \*STDERR,
 		out => \*STDOUT,
-		grouplist => [],
 		pi_config => $pi_config,
 		servername => $name,
 		greet => \"201 $name ready - post via email\r\n",
@@ -60,9 +59,7 @@ sub refresh_groups {
 			delete $groups->{$ngname};
 		}
 	});
-	my @names = sort(keys %$groups);
-	$self->{grouplist} = [ map { $groups->{$_} } @names ];
-	$self->{groupnames} = \@names;
+	$self->{groupnames} = [ sort(keys %$groups) ];
 	$self->{pi_config} = $pi_config;
 	# this will destroy old groups that got deleted
 	$self->{groups} = $groups;
diff --git a/t/nntp.t b/t/nntp.t
index 91a2aff7..ea2ef876 100644
--- a/t/nntp.t
+++ b/t/nntp.t
@@ -112,7 +112,6 @@ use PublicInbox::Config;
 	my $hdr = $mime->header_obj;
 	my $mock_self = {
 		nntpd => {
-			grouplist => [],
 			servername => 'example.com',
 			pi_config => bless {}, 'PublicInbox::Config',
 		},

  reply	other threads:[~2020-11-28  5:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-28  5:09 [PATCH 0/5] nntp: round 2 of ->ALL extindex speedups Eric Wong
2020-11-28  5:09 ` Eric Wong [this message]
2020-11-28  5:09 ` [PATCH 2/5] nntp: speed up mid_lookup() using ->ALL extindex Eric Wong
2020-11-28  5:09 ` [PATCH 3/5] nntp: art_lookup: use mid_lookup and simplify Eric Wong
2020-11-28  5:09 ` [PATCH 4/5] nntp: XPATH uses ->ALL extindex, too Eric Wong
2020-11-28  5:09 ` [PATCH 5/5] nntpd: remove redundant {groups} shortcut Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201128050916.5586-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).