Use splice on the array, so that we don't get try to fill in the array
slice with null elements when we have too few moods.
Patch by fu.
diffs (29 lines):
diff -r a7aa86b62ca8 -r b9ed7da790c2 cgi-bin/DW/Controller/Latest/Mood.pm
--- a/cgi-bin/DW/Controller/Latest/Mood.pm Thu Jul 29 01:20:07 2010 -0700
+++ b/cgi-bin/DW/Controller/Latest/Mood.pm Thu Jul 29 01:50:10 2010 -0700
@@ -44,6 +44,7 @@ sub mood_handler {
my $moods = LJ::MemCache::get( "latest_moods" ) || [];
my $out = {};
+ my $num_top = 5;
if ( scalar @$moods ) {
my %counts;
@@ -58,7 +59,7 @@ sub mood_handler {
}
my @names = sort { $counts{$b} <=> $counts{$a} || $a cmp $b } keys
%counts;
- my %top_counts = map { ($_,$counts{$_}) } @names[0..5];
+ my %top_counts = map { ($_,$counts{$_}) } splice( @names, 0, $num_top
);
my @top_mood;
foreach my $mood ( @names ) {
if ( $counts{$mood} == $counts{$names[0]} ) {
@@ -71,7 +72,7 @@ sub mood_handler {
$out->{counts} = \%top_counts;
$out->{score} = int($score / $count);
$out->{score} = $r->get_args->{score} if defined $r->get_args->{score};
- $out->{highest} = [ @names[0..5] ];
+ $out->{highest} = [ splice( @names, 0, $num_top ) ];
$out->{top_mood} = \...@top_mood;
} else {
$out->{no_data} = 1;
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog