From 67ecd56a0aaf977fa1a22aa6e2378c9317c72549 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 28 Nov 2023 14:56:21 +0000 Subject: www: load and use cindex join data This is a major step in solving the problem of having to manually associate hundreds/thousands of coderepos with hundreds/thousands of public-inboxes to power solver (and more). --- lib/PublicInbox/Config.pm | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'lib/PublicInbox/Config.pm') diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 9bee94b8..779e3140 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -412,8 +412,8 @@ sub get_1 { sub repo_objs { my ($self, $ibxish) = @_; - my $ibx_coderepos = $ibxish->{coderepo} // return; $ibxish->{-repo_objs} // do { + my $ibx_coderepos = $ibxish->{coderepo} // return; parse_cgitrc($self, undef, 0); my $coderepos = $self->{-coderepos}; my @repo_objs; @@ -568,6 +568,43 @@ sub _fill_ei ($$) { $es; } +sub _fill_csrch ($$) { + my ($self, $name) = @_; # "" is a valid name for cindex + return if $name ne '' && !valid_foo_name($name, 'cindex'); + eval { require PublicInbox::CodeSearch } or return; + my $pfx = "cindex.$name"; + my $d = $self->{"$pfx.topdir"} // return; + -d $d or return; + if (index($d, "\n") >= 0) { + warn "E: `$d' must not contain `\\n'\n"; + return; + } + my $csrch = PublicInbox::CodeSearch->new($d, $self); + for my $k (qw(localprefix)) { + my $v = $self->{"$pfx.$k"} // next; + $csrch->{$k} = _array($v); + } + $csrch->{name} = $name; + $csrch; +} + +sub lookup_cindex ($$) { + my ($self, $name) = @_; + $self->{-csrch_by_name}->{$name} //= _fill_csrch($self, $name); +} + +sub each_cindex { + my ($self, $cb, @arg) = @_; + my @csrch = map { + lookup_cindex($self, substr($_, length('cindex.'))) // () + } grep(m!\Acindex\.[^\./]*\z!, @{$self->{-section_order}}); + if (ref($cb) eq 'CODE') { + $cb->($_, @arg) for @csrch; + } else { # string function + $_->$cb(@arg) for @csrch; + } +} + sub config_cmd { my ($self, $env, $opt) = @_; my $f = $self->{-f} // default_file(); -- cgit v1.2.3-24-ge0c7