From 0c959fa07e7bf3e072a03f71acd7fc78cf52d2ff Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 28 Oct 2024 20:47:58 +0000 Subject: [PATCH] coderepo: sort per-inbox coderepos by score This increases the likelyhood of early solver success and looks more logical in listings. It's probably OK to ditch the timestamp column since the score is far more important and we can reduce Xapians lookups this way. The raw score is still shown, for now, but that could probably be a percentage in the future... --- lib/PublicInbox/CodeSearch.pm | 11 +++++++++++ lib/PublicInbox/WwwText.pm | 6 ++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/CodeSearch.pm b/lib/PublicInbox/CodeSearch.pm index 3838fd1b0..2200262d0 100644 --- a/lib/PublicInbox/CodeSearch.pm +++ b/lib/PublicInbox/CodeSearch.pm @@ -266,6 +266,15 @@ sub load_commit_times { # each_cindex callback @$todo = @pending; } +# sort per-inbox scores from public-inbox-cindex --join +sub _cr_score_sort ($$) { + my ($gits, $cr_score) = @_; + use sort 'stable'; # preserve manual ordering in config file + @$gits = sort { + $cr_score->{$b->{nick}} <=> $cr_score->{$a->{nick}} + } @$gits; +} + sub load_coderepos { # each_cindex callback my ($self, $pi_cfg) = @_; my $name = $self->{name}; @@ -341,6 +350,7 @@ EOM } if (@$gits) { push @{$ibx->{-csrch}}, $self if $ibx2self; + _cr_score_sort $gits, $cr_score; } else { delete $ibx->{-repo_objs}; delete $ibx->{-cr_score}; @@ -359,6 +369,7 @@ EOM push @$gits, @alls_gits; my $cr_score = $ALL->{-cr_score} //= {}; $cr_score->{$_->{nick}} //= scalar(@{$_->{ibx_score}//[]}) for @$gits; + _cr_score_sort $gits, $cr_score; } sub repos_sorted { diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm index 79fe46aab..172f5025a 100644 --- a/lib/PublicInbox/WwwText.pm +++ b/lib/PublicInbox/WwwText.pm @@ -227,17 +227,15 @@ sub coderepos_raw ($$) { my $cr = $cfg->repo_objs($ctx->{ibx}) or return (); my $buf = 'Code repositories for project(s) associated with this '. $ctx->{ibx}->thing_type . ":\n"; - my @recs = PublicInbox::CodeSearch::repos_sorted($cfg, @$cr); my $cr_score = $ctx->{ibx}->{-cr_score}; my $env = $ctx->{env}; - for (@recs) { - my ($t, $git) = @$_; + for my $git (@$cr) { for ($git->pub_urls($env)) { my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ : $top_url.$_; my $nr = $cr_score->{$git->{nick}}; $buf .= "\n"; $buf .= $nr ? sprintf('% 9u', $nr) : (' 'x9); - $buf .= ' '.fmt_ts($t).' '.prurl($env, $u); + $buf .= ' '.prurl($env, $u); } } ($buf); -- 2.47.2