fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-08-19 09:53 am

[dw-free] Warnings in logs from latest moods, when there aren't enough moods to fill the latest mood

[commit: http://hg.dwscoalition.org/dw-free/rev/0acbf04e2b68]

http://bugs.dwscoalition.org/show_bug.cgi?id=2968

Just going by number of moods isn't enough, because duplicated moods are
counted twice. So we need to count the number of aggregated moods.

Patch by [personal profile] fu.

Files modified:
  • cgi-bin/DW/Controller/Latest/Mood.pm
--------------------------------------------------------------------------------
diff -r e1529b5ec542 -r 0acbf04e2b68 cgi-bin/DW/Controller/Latest/Mood.pm
--- a/cgi-bin/DW/Controller/Latest/Mood.pm	Thu Aug 19 17:32:31 2010 +0800
+++ b/cgi-bin/DW/Controller/Latest/Mood.pm	Thu Aug 19 17:53:28 2010 +0800
@@ -50,7 +50,6 @@ sub mood_handler {
     if ( $count ) {
         my %counts;
         my $score = 0;
-        my $to_show = $count > $num_top ? $num_top : $count;
 
         my $metadata = DW::Mood->get_moods;
 
@@ -59,7 +58,10 @@ sub mood_handler {
             $counts{$metadata->{$moodid}->{name}}++;
         }
 
-        my @names = sort { $counts{$b} <=> $counts{$a} || $a cmp $b } keys %counts;
+        my @counts_keys = keys %counts;
+        my $to_show = scalar @counts_keys > $num_top ? $num_top : scalar @counts_keys;
+
+        my @names = sort { $counts{$b} <=> $counts{$a} || $a cmp $b } @counts_keys;
         my @highest = @names[0..( $to_show - 1)];
         my %top_counts = map { ($_,$counts{$_}) } @highest;
         my @top_mood;
--------------------------------------------------------------------------------