Fix bugs with creating random user fairy data.

        Patch by janinedog. 

diffs (51 lines):

diff -r 0b3288e64770 -r d48f49dad17b bin/get-users-for-paid-accounts.pl
--- a/bin/get-users-for-paid-accounts.pl        Wed Aug 19 10:55:24 2009 -0500
+++ b/bin/get-users-for-paid-accounts.pl        Wed Aug 19 16:45:42 2009 +0000
@@ -17,27 +17,30 @@ my $week_ago = $starttime - 60*60*24*7;
 my $week_ago = $starttime - 60*60*24*7;
 my $month_ago = $starttime - 60*60*24*30;
 
-my $us = LJ::load_userids( @$userids );
-foreach my $userid ( keys %$us ) {
-    my $u = $us->{$userid};
+while ( @$userids && ( my @userids_chunk = splice( @$userids, 0, 100 ) ) ) {
+    my $us = LJ::load_userids( @userids_chunk );
+    foreach my $userid ( keys %$us ) {
+        my $u = $us->{$userid};
 
-    next if $u->is_paid; # must not be a paid user
-    next unless $u->opt_randompaidgifts; # must allow random paid gifts
-    next if LJ::sysban_check( 'pay_user', $u->user ); # must not be sysbanned 
from payments
-    next if $u->timecreate > $month_ago; # must be created more than a month 
ago
-    next if $u->number_of_posts < 10; # must have at least 10 posts
-    next if $u->timeupdate < $week_ago; # must have posted in the past week
+        next if $u->is_paid; # must not be a paid user
+        next unless $u->opt_randompaidgifts; # must allow random paid gifts
+        next if LJ::sysban_check( 'pay_user', $u->user ); # must not be 
sysbanned from payments
+        next if $u->timecreate > $month_ago; # must be created more than a 
month ago
+        next if $u->number_of_posts < 10; # must have at least 10 posts
+        next if $u->timeupdate < $week_ago; # must have posted in the past week
 
-    # get the number of entries posted and comments left in the past month
-    my $num_posts = $dbslow->selectrow_array( "SELECT COUNT(*) FROM log2 WHERE 
journalid = ? AND logtime > ?", undef, $userid, LJ::mysql_time( $month_ago ) );
-    my $num_comments = $dbslow->selectrow_array( "SELECT COUNT(*) FROM 
talkleft WHERE userid = ? AND posttime > ?", undef, $userid, $month_ago );
+        # get the number of entries posted and comments left in the past month
+        my $dbcr = LJ::get_cluster_reader( $u );
+        my $num_posts = $dbcr->selectrow_array( "SELECT COUNT(*) FROM log2 
WHERE journalid = ? AND logtime > ?", undef, $userid, LJ::mysql_time( 
$month_ago ) );
+        my $num_comments = $dbcr->selectrow_array( "SELECT COUNT(*) FROM 
talkleft WHERE userid = ? AND posttime > ?", undef, $userid, $month_ago );
 
-    # assign point values based on these numbers
-    my $post_points = min( 10, $num_posts ) || 0;
-    my $comment_points = min( 10, $num_comments ) || 0;
+        # assign point values based on these numbers
+        my $post_points = min( 10, $num_posts ) || 0;
+        my $comment_points = min( 10, $num_comments ) || 0;
 
-    # insert the total points for the user
-    $dbh->do( "INSERT INTO users_for_paid_accounts ( userid, time_inserted, 
points ) VALUES ( ?, ?, ? )", undef, $userid, $starttime, $post_points + 
$comment_points );
+        # insert the total points for the user
+        $dbh->do( "INSERT INTO users_for_paid_accounts ( userid, 
time_inserted, points ) VALUES ( ?, ?, ? )", undef, $userid, $starttime, 
$post_points + $comment_points );
+    }
 }
 
 # delete all old data
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to