summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2022-06-26 11:11:07 +0200
committerYorhel <git@yorhel.nl>2022-06-26 11:11:09 +0200
commit055e526a9a0e8cdb54285eec0441c5a04b1281e4 (patch)
treeeb2248acf2b3141ce952747c14e029ca0c17af9d
parent3bf09a32b66cce0f02c5f7245b0a4afbb77e5db1 (diff)
Fix ordering of patch releases + releases list on producer pagesHEADmaster
Fixes https://vndb.org/t950.1289 and https://vndb.org/t950.1290
-rw-r--r--lib/VNWeb/Producers/Page.pm9
-rw-r--r--lib/VNWeb/Releases/Lib.pm17
-rw-r--r--lib/VNWeb/VN/Page.pm9
3 files changed, 21 insertions, 14 deletions
diff --git a/lib/VNWeb/Producers/Page.pm b/lib/VNWeb/Producers/Page.pm
index 4e8000e3..a0e69216 100644
--- a/lib/VNWeb/Producers/Page.pm
+++ b/lib/VNWeb/Producers/Page.pm
@@ -72,7 +72,7 @@ sub rel_ {
FROM releases r
JOIN releases_producers rp ON rp.id = r.id
WHERE rp.pid =', \$p->{id}, ' AND NOT r.hidden
- ORDER BY r.released, r.title, r.id
+ ORDER BY r.released
');
$_->{rtype} = 1 for @$r; # prevent enrich_release() from fetching rtypes
enrich_extlinks r => $r;
@@ -104,10 +104,9 @@ sub rel_ {
a_ href => "/$v->{id}", title => $v->{alttitle}||$v->{title}, $v->{title};
};
my $ropt = { id => $v->{id}, prod => 1 };
- for my $rel ($vn{$v->{id}}->@*) {
- $rel->[1]{rtype} = $rel->[0];
- release_row_ $rel->[1], $ropt;
- }
+ release_row_ $_, $ropt for sort_releases(
+ [ map { $_->[1]{rtype} = $_->[0]; $_->[1] } $vn{$v->{id}}->@* ]
+ )->@*;
};
}
} if @$r;
diff --git a/lib/VNWeb/Releases/Lib.pm b/lib/VNWeb/Releases/Lib.pm
index f6c20240..20432c42 100644
--- a/lib/VNWeb/Releases/Lib.pm
+++ b/lib/VNWeb/Releases/Lib.pm
@@ -3,7 +3,7 @@ package VNWeb::Releases::Lib;
use VNWeb::Prelude;
use Exporter 'import';
-our @EXPORT = qw/enrich_release_elm releases_by_vn enrich_release release_row_/;
+our @EXPORT = qw/enrich_release_elm releases_by_vn enrich_release sort_releases release_row_/;
# Enrich a list of releases so that it's suitable as 'Releases' Elm response.
@@ -39,6 +39,21 @@ sub enrich_release {
}
+# Sort an array of releases, assumes the objects come from enrich_release()
+# (Not always possible with an SQL ORDER BY due to rtype being context-dependent and platforms coming from other tables)
+sub sort_releases {
+ return [ sort {
+ $a->{released} <=> $b->{released} ||
+ $b->{rtype} cmp $a->{rtype} ||
+ $b->{official} cmp $a->{official} ||
+ $a->{patch} cmp $b->{patch} ||
+ ($a->{platforms}[0]||'') cmp ($b->{platforms}[0]||'') ||
+ $a->{title} cmp $b->{title} ||
+ idcmp($a->{id}, $b->{id})
+ } $_[0]->@* ];
+}
+
+
sub release_extlinks_ {
my($r, $id) = @_;
return if !$r->{extlinks}->@*;
diff --git a/lib/VNWeb/VN/Page.pm b/lib/VNWeb/VN/Page.pm
index 4b820145..45a437ba 100644
--- a/lib/VNWeb/VN/Page.pm
+++ b/lib/VNWeb/VN/Page.pm
@@ -505,14 +505,7 @@ sub releases_ {
# TODO: Organize a long list of releases a bit better somehow? Collapsable language sections?
enrich_release $v->{releases};
- $v->{releases} = [ sort {
- $a->{released} <=> $b->{released} ||
- $b->{rtype} cmp $a->{rtype} ||
- $b->{official} cmp $a->{official} ||
- ($a->{platforms}[0]||'') cmp ($b->{platforms}[0]||'') ||
- $a->{title} cmp $b->{title} ||
- idcmp($a->{id}, $b->{id})
- } $v->{releases}->@* ];
+ $v->{releases} = sort_releases $v->{releases};
my(%lang, %langrel, %langmtl);
for my $r ($v->{releases}->@*) {