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 ); 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 ) { sub shufflePostsIfRequired ( $self, $category, $posts ) {
my $pinned_posts = [ my $pinned_posts = [
sort { $b->{pinned} <=> $a->{pinned} } sort { $self->comparePinned( $a, $b ) }
grep { defined $_->{pinned} } @$posts grep { defined $_->{pinned} } @$posts
]; ];
$posts = [ grep { !exists $_->{pinned} } @$posts ]; $posts = [ grep { !exists $_->{pinned} } @$posts ];
@ -205,7 +213,7 @@ sub RetrieveDirectPostsForCategory ( $self, $category_name ) {
} }
my $posts = $post_by_category->{$category_name}; my $posts = $post_by_category->{$category_name};
$posts //= []; $posts //= [];
return $self->shufflePostsIfRequired($category, [@$posts]); return $self->shufflePostsIfRequired( $category, [@$posts] );
} }
sub PreviewOg { sub PreviewOg {