Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[fotobilder] r1444: decrease contest for locks on table 'cha...

Committer: gariev
decrease contest for locks on table 'challenges'
U   trunk/lib/FB/User.pm
Modified: trunk/lib/FB/User.pm
===================================================================
--- trunk/lib/FB/User.pm	2011-05-25 04:10:51 UTC (rev 1443)
+++ trunk/lib/FB/User.pm	2011-05-25 06:25:43 UTC (rev 1444)
@@ -761,9 +761,12 @@
 sub generate_challenge {
     my $u = shift;
 
-    $u->do("DELETE FROM challenges WHERE userid=? AND ".
-           "timecreate < UNIX_TIMESTAMP()-60",
-           $u->{'userid'});
+    # decrease contest for table 'challenges'
+    if (rand()<0.1) {
+        $u->do("DELETE FROM challenges WHERE userid=? AND ".
+               "timecreate < UNIX_TIMESTAMP()-60",
+               $u->{'userid'});
+    }
 
     my $chal = FB::rand_chars(40);
     my $auth = FB::domain_plugin($u);
@@ -1855,9 +1858,11 @@
     my $db = $u ? FB::get_user_db_writer($u) : FB::get_db_writer();
     return undef unless $db;
     if ($u) {
-        $db->do("DELETE FROM challenges WHERE userid=? AND ".
-                "timecreate < UNIX_TIMESTAMP()-60",
-                undef, $u->{'userid'});
+        if (rand()<0.1) {
+            $db->do("DELETE FROM challenges WHERE userid=? AND ".
+                    "timecreate < UNIX_TIMESTAMP()-60",
+                    undef, $u->{'userid'});
+        }
     } else {
         $db->do("DELETE FROM challengesanon WHERE ".
                 "timecreate < UNIX_TIMESTAMP()-120");
@@ -1994,7 +1999,8 @@
                 $extra = "AND resp=" . $db->quote($res);
             }
             $del = $db->do("DELETE FROM challenges WHERE userid=? AND challenge=? ".
-                           $extra, undef, $u->{'userid'}, $chal);
+                            " AND timecreate < UNIX_TIMESTAMP()-60 " . $extra, 
+                            undef, $u->{'userid'}, $chal);
         }
         return undef unless $del > 0;
         return $u; # true, but also useful if caller only had $user

Tags: fotobilder, gariev, 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