Alexander Nazarov (nfokz) wrote in changelog,
Alexander Nazarov
nfokz
changelog

[ljcom] r11101: LJSUP-6301: Purge innactive accounts

Committer: anazarov
LJSUP-6301: Purge innactive accounts
U   trunk/bin/maint/inactive.pl
Modified: trunk/bin/maint/inactive.pl
===================================================================
--- trunk/bin/maint/inactive.pl	2011-10-17 10:03:15 UTC (rev 11100)
+++ trunk/bin/maint/inactive.pl	2011-10-17 13:30:36 UTC (rev 11101)
@@ -7,6 +7,8 @@
 use LJ::User::Inactive;
 
 my $work = sub {
+    LJ::start_request();
+
     my $dbh = LJ::get_db_writer();
     $dbh->{'RaiseError'} = 1;
 
@@ -17,48 +19,41 @@
 
     $max_handled_userid ||= 0;
 
+    my $inactive_account_seconds =
+        LJ::User::Inactive::SECONDS_IN_MONTH *
+        $LJ::INACTIVE_ACCOUNT_MONTHS;
+
     #TODO: magic number 10000
-    my $res = $dbh->selectall_arrayref(qq{
-        SELECT userid, UNIX_TIMESTAMP(timecreate) AS timecreate
+    my ($userid, $timestamp);
+    my $sth = $dbh->prepare(qq{
+        SELECT userid, UNIX_TIMESTAMP(timecreate)
         FROM userusage
-        WHERE userid > $max_handled_userid
+        WHERE userid > ?
         ORDER BY userid
         LIMIT 10000
-    }, { 'Slice' => {} });
+    });
 
-    my $affected = scalar @$res;
+    $sth->execute($max_handled_userid);
+    $sth->bind_columns(\($userid, $timestamp));
 
-    foreach my $row (@$res) {
-        my $inactive_account_seconds =
-            LJ::User::Inactive::SECONDS_IN_MONTH *
-            $LJ::INACTIVE_ACCOUNT_MONTHS;
-
-        my $time = $row->{'timecreate'} + $inactive_account_seconds;
-        $dbh->do(
-            qq{
+    while ($sth->fetch) {
+        my $time = $timestamp + $inactive_account_seconds;
+        $dbh->do(qq{
                 REPLACE INTO user_active_until
                 SET userid=?, policyver=?, until=?
-            }, undef, $row->{'userid'},
+            }, undef, $userid,
             LJ::User::Inactive::POLICY_VERSION, $time
         );
     }
 
-    return $affected;
+    LJ::end_request();
+
+    return $userid ? 1 : 0;
 };
 
 $maint{'inactive_populate_active'} = sub {
-    return if $LJ::DISABLED{'purge_inactive'};
-
-    my $affected;
-
-    do {
-        LJ::start_request();
-
-        $affected = 1;
-
-        eval { $affected = $work->() };
-        warn $@ if $@;
-
-        LJ::end_request();
-    } while ($affected);
+    eval { 
+        while ( $work->() ) { 1 };
+    };
+    warn $@ if $@;
 };

Tags: anazarov, ljcom, nfokz, pl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments