juks (juks) wrote in changelog,
juks
juks
changelog

[livejournal] r18660: LJSUP-8195 E-mail unsubscription

Committer: iaskarov
LJSUP-8195 E-mail unsubscription
U   trunk/bin/worker/email-status
U   trunk/cgi-bin/LJ/User/EmailStatus.pm
U   trunk/htdocs/register.bml
Modified: trunk/bin/worker/email-status
===================================================================
--- trunk/bin/worker/email-status	2011-03-22 05:24:33 UTC (rev 18659)
+++ trunk/bin/worker/email-status	2011-03-22 05:40:38 UTC (rev 18660)
@@ -21,18 +21,13 @@
     my ($class, $job) = @_;
     my $args = $job->arg;
 
-	warn "GOT A JOB";
+    if(!$args->{email}) {
+	die("TheSchwartz::Worker::EmailStatus: No Email");		
+    }
 	
-	if(!$args->{email}) {
-		warn "TheSchwartz::Worker::EmailStatus: No Email";
+    LJ::User::EmailStatus->change_email_users_status(email => $args->{email}, disabled => $args->{disabled});
 		
-		$job->completed;
-		return;
-	}
-	
-	LJ::User::EmailStatus->change_email_users_status(email => $args->{email}, disabled => $args->{disabled});
-		
-	$job->completed;
+    $job->completed;
     return;
 }
 

Modified: trunk/cgi-bin/LJ/User/EmailStatus.pm
===================================================================
--- trunk/cgi-bin/LJ/User/EmailStatus.pm	2011-03-22 05:24:33 UTC (rev 18659)
+++ trunk/cgi-bin/LJ/User/EmailStatus.pm	2011-03-22 05:40:38 UTC (rev 18660)
@@ -1,11 +1,6 @@
 package LJ::User::EmailStatus;
 use strict;
 
-my $max_error_count     = 3;                    # After this amount of smtp errors, occured within the faulty_period, the email status will be changed
-my $cache_time          = 86400;                # Memcached storage time
-my $faulty_period       = 86400 * 7;            # Minimal period, within the max_error_count should occur to cause the email status change
-my $max_faulty_period   = 86400 * 30;           # Maximal statistics storage time for the email
-
 #
 #   Handles SMTP code for some recipient email
 #
@@ -21,7 +16,7 @@
     my $cache_key = $class->get_cache_key($params{email});
     
     my $dbh;
-    my $data = undef; #'LJ::MemCache::get($cache_key);
+    my $data = LJ::MemCache::get($cache_key);
     
     unless (defined $data) {
         $dbh = LJ::get_db_writer() or die ('Failed to get db connection');
@@ -36,9 +31,9 @@
 
     # Address error count is increasing
     if ($params{code} == 5) {
-        $dbh = LJ::get_db_writer() or die ('Failed to get db connection') if(!$dbh);
+        $dbh ||= LJ::get_db_writer() or die ('Failed to get db connection');
              
-        if (!$data->{error_count} || time() - $data->{last_error_time} > $max_faulty_period) {
+        if (!$data->{error_count} || time() - $data->{last_error_time} > $LJ::EMAIL_MAX_FAULTY_PERIOD) {
             $data->{error_count}        = 1;
             $data->{first_error_time}   = time();
             $data->{last_error_time}    = time();
@@ -52,7 +47,7 @@
             $data->{last_error_time}  = time();
 
             # Should put down this email if it is too faulty within minimum period of time
-            if ($data->{error_count} >= $max_error_count && ($data->{last_error_time} - $data->{first_error_time} > $faulty_period)) {
+            if ($data->{error_count} >= $LJ::EMAIL_MAX_ERROR_COUNT && ($data->{last_error_time} - $data->{first_error_time} > $LJ::EMAIL_FAULTY_PERIOD)) {
                 $data->{disabled}         = 1;
                 $class->process_disabled_status(%params, disabled => 1);
             }
@@ -63,7 +58,7 @@
                     ) or die('Failed to update record');
         }
         
-        LJ::MemCache::set($cache_key, $data, $cache_time);
+        LJ::MemCache::set($cache_key, $data, $LJ::EMAIL_STATUS_CACHE_TIME);
     # Address became OK, being faulty before
     } elsif ($data->{error_count}) {
         $dbh = LJ::get_db_writer() or die ('Failed to get db connection') if(!$dbh);
@@ -75,7 +70,10 @@
 
         $data->{error_count} = 0;
         
-        LJ::MemCache::set($cache_key, $data, $cache_time);
+        LJ::MemCache::set($cache_key, $data, $LJ::EMAIL_STATUS_CACHE_TIME);
+    # Address is just OK
+    } else {
+        LJ::MemCache::set($cache_key, {error_count => 0}, $LJ::EMAIL_STATUS_CACHE_TIME);
     }
 }
 
@@ -105,7 +103,7 @@
 }
 
 #
-#   Change email users status
+#   Perfom some operations on the accounts, using affected addresses
 #
 sub change_email_users_status {
     my ($class, %params) = @_;
@@ -142,7 +140,7 @@
 }
 
 #
-#   Get Cache key
+#   Get Memcached cache key based on email address
 #
 sub get_cache_key {
     my ($class, $email) = @_;
@@ -156,9 +154,9 @@
 sub cleanup {
     my $dbh = LJ::get_db_writer() or die ('Failed to get db connection');
     
-    $dbh->do("DELETE FROM email_status WHERE unix_timestamp() - first_error_time > ?",
+    $dbh->do("DELETE FROM email_status WHERE unix_timestamp() - first_error_time > ? LIMIT 5000",
                 undef,
-                $max_faulty_period
+                $LJ::EMAIL_MAX_FAULTY_PERIOD
              );  
 }
 

Modified: trunk/htdocs/register.bml
===================================================================
--- trunk/htdocs/register.bml	2011-03-22 05:24:33 UTC (rev 18659)
+++ trunk/htdocs/register.bml	2011-03-22 05:40:38 UTC (rev 18660)
@@ -107,7 +107,6 @@
      }
 
      LJ::User::EmailStatus->change_email_users_status(email => $u->email_raw, user => $u);
-     #LJ::update_user($u, { status => 'A' });
      
      $u->update_email_alias;
      LJ::run_hook('email_verified', $u);

Tags: bml, juks, livejournal, pm
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