]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
indexheader: deduplicate common values
authorEric Wong <e@80x24.org>
Sat, 10 Aug 2024 09:00:03 +0000 (09:00 +0000)
committerEric Wong <e@80x24.org>
Sat, 17 Aug 2024 17:36:14 +0000 (17:36 +0000)
Since we plan on sharing IndexHeader across multiple inboxes for
large installations with thousands of inboxes, it makes sense to
deduplicate the values to save some memory at the cost of
increased startup time.

lib/PublicInbox/IndexHeader.pm

index 53e9373bd4e7aa98ae9403c0f354297c5f485ba9..07827959b8c4a87dccc49e0ebdaf89a90b8e8eb7 100644 (file)
@@ -17,7 +17,8 @@ sub extra_indexer_new_common ($$$$) {
        my ($self, $spec, $pfx, $query) = @_;
        $pfx =~ /\A[a-z][a-z0-9]*\z/ or
                warn "W: non-word prefix in `$spec' not searchable\n";
-       $self->{prefix} = $pfx;
+       my %dedupe = ($pfx => undef);
+       ($self->{prefix}) = keys %dedupe;
        my %params = map {
                my ($k, $v) = split /=/, uri_unescape($_), 2;
                ($k, $v // '');
@@ -25,7 +26,8 @@ sub extra_indexer_new_common ($$$$) {
        my $xpfx = delete($params{index_prefix}) // "X\U$pfx";
        $xpfx =~ /\A[A-Z][A-Z0-9]*\z/ or die
                die "E: `index_prefix' in `$spec' must be ALL CAPS\n";
-       $self->{xprefix} = $xpfx;
+       %dedupe = ($xpfx => undef);
+       ($self->{xprefix}) = keys %dedupe;
        \%params;
 }
 
@@ -34,14 +36,18 @@ sub new {
        my ($type, $pfx, $header, $query) = split /:/, $spec, 4;
        $pfx // die "E: `$spec' has no user prefix\n";
        $header // die "E: `$spec' has no mail header\n";
+       $T2IDX{$type} // die
+               "E: `$type' not supported in $spec, must be one of: ",
+               join(', ', sort keys %T2IDX), "\n";
+       my %dedupe = ($type => undef);
+       ($type) = keys %dedupe;
+       %dedupe = ($header => undef);
+       ($header) = keys %dedupe;
        my $self = bless { header => $header, type => $type }, $cls;
        my $params = extra_indexer_new_common $self, $spec, $pfx, $query;
        $self->{hdr_method} = delete $params->{raw} ? 'header_raw' : 'header';
        my @k = keys %$params;
        warn "W: unknown params in `$spec': ", join(', ', @k), "\n" if @k;
-       $T2IDX{$type} // die
-               "E: `$type' not supported in $spec, must be one of: ",
-               join(', ', sort keys %T2IDX), "\n";
        $self;
 }