]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
coderepo: sort per-inbox coderepos by score
authorEric Wong <e@80x24.org>
Mon, 28 Oct 2024 20:47:58 +0000 (20:47 +0000)
committerEric Wong <e@80x24.org>
Thu, 31 Oct 2024 18:10:04 +0000 (18:10 +0000)
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
lib/PublicInbox/WwwText.pm

index 3838fd1b056de2d33846241f121808005f8b442d..2200262d0599e859e8ce0392bee59b98efe2e91a 100644 (file)
@@ -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 {
index 79fe46aab4185f67e146a9a859bd48ac8cd318cd..172f5025ae900e8094aa75f74a2ffd9824043f87 100644 (file)
@@ -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);