Adding between same pinned value shuffle.

This commit is contained in:
Sergiotarxz 2023-09-17 06:07:16 +02:00
parent 2bc7c60246
commit dcca9c89d6

View File

@ -183,9 +183,17 @@ sub RetrieveAllPostsForCategory ( $self, $category_name ) {
return $self->shufflePostsIfRequired( $category, $posts );
}
sub comparePinned ( $self, $a, $b ) {
my $cmp = $b->{pinned} <=> $a->{pinned};
if ( $cmp != 0 ) {
return $cmp;
}
return int( rand(3) ) - 1;
}
sub shufflePostsIfRequired ( $self, $category, $posts ) {
my $pinned_posts = [
sort { $b->{pinned} <=> $a->{pinned} }
sort { $self->comparePinned( $a, $b ) }
grep { defined $_->{pinned} } @$posts
];
$posts = [ grep { !exists $_->{pinned} } @$posts ];