Some more tweaking of prelim memcached support; shortened keys, added newtalk for...
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 13 Aug 2003 12:26:06 +0000 (12:26 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 13 Aug 2003 12:26:06 +0000 (12:26 +0000)
includes/LinkCache.php
includes/User.php
includes/UserTalkUpdate.php

index 62bf9de..fdac736 100644 (file)
@@ -63,7 +63,7 @@ class LinkCache {
                        unset( $this->mBadLinks[$index] );
                }
                global $wgMemc, $wgDBname;
-               $wgMemc->delete( "$wgDBname:linkcache:title:$title" );
+               $wgMemc->delete( "$wgDBname:lc:title:$title" );
        }
 
        function suspend() { $this->mActive = false; }
@@ -87,7 +87,7 @@ class LinkCache {
 
                if ( "" == $t ) { return 0; }
 
-               $id = $wgMemc->get( $key = "$wgDBname:linkcache:title:$title" );
+               $id = $wgMemc->get( $key = "$wgDBname:lc:title:$title" );
                if( $id === FALSE ) {
                        $sql = "SELECT HIGH_PRIORITY cur_id FROM cur WHERE cur_namespace=" .
                          "{$ns} AND cur_title='" . wfStrencode( $t ) . "'";
index ffef535..1fefe2b 100644 (file)
@@ -156,7 +156,7 @@ class User {
                }
 
                $passwordCorrect = FALSE;
-               $user = $wgMemc->get( $key = "$wgDBname:user:user_id:$sId" );
+               $user = $wgMemc->get( $key = "$wgDBname:user:id:$sId" );
                if($makenew = !$user) {
                        wfDebug( "User::loadFromSession() unable to load from memcached\n" );
                        $user = new User();
@@ -202,13 +202,20 @@ class User {
                        }
                        wfFreeResult( $res );
                } else {
-                       $sql = "SELECT 1 FROM user_newtalk WHERE user_ip='{$this->mName}'";
-                       $res = wfQuery ($sql,  "User::loadFromDatabase" );
+                       global $wgDBname, $wgMemc;
+                       $key = "$wgDBname:newtalk:ip:{$this->mName}";
+                       $newtalk = $wgMemc->get( $key );
+                       if($newtalk === false) {
+                               $sql = "SELECT 1 FROM user_newtalk WHERE user_ip='{$this->mName}'";
+                               $res = wfQuery ($sql,  "User::loadFromDatabase" );
 
-                       if (wfNumRows($res)>0) {
-                               $this->mNewtalk= 1;
+                               $this->mNewtalk = (wfNumRows($res)>0) ? 1 : 0;
+                               wfFreeResult( $res );
+
+                               $wgMemc->set( $key, $this->mNewtalk, time() ); // + 1800 );
+                       } else {
+                               $this->mNewtalk = $newtalk ? 1 : 0;
                        }
-                       wfFreeResult( $res );
                }
                if(!$this->mId) {
                        $this->mDataLoaded = true;
@@ -509,6 +516,7 @@ class User {
                        } else {
                                $sql="DELETE FROM user_newtalk WHERE user_ip='{$this->mName}'";
                                wfQuery ($sql,"User::saveSettings");
+                               $wgMemc->delete( "$wgDBname:newtalk:ip:{$this->mName}" );
                        }
                }
                if ( 0 == $this->mId ) { return; }
@@ -524,8 +532,8 @@ class User {
                  "user_touched= '" . wfStrencode( $this->mTouched ) .
                  "' WHERE user_id={$this->mId}";
                wfQuery( $sql, "User::saveSettings" );
-               #$wgMemc->replace( "$wgDBname:user:user_id:$this->mId", $this );
-               $wgMemc->delete( "$wgDBname:user:user_id:$this->mId" );
+               #$wgMemc->replace( "$wgDBname:user:id:$this->mId", $this );
+               $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
        }
 
        # Checks if a user with the given name exists
index 777f5f4..70c8486 100644 (file)
@@ -38,14 +38,13 @@ class UserTalkUpdate {
                                $user->setID(User::idFromName($this->mTitle));
                                if ($id=$user->getID()) {                                                                       
                                        $sql = "INSERT INTO user_newtalk (user_id) values ({$id})";
-                                       $wgMemc->delete( "$wgDBname:user:user_id:$id" );
-                               } else { #anon
-                                       
+                                       $wgMemc->delete( "$wgDBname:user:id:$id" );
+                               } else {
+                                       #anon
                                        if(preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$this->mTitle)) { #real anon (user:xxx.xxx.xxx.xxx)
-                                       
                                                $sql = "INSERT INTO user_newtalk (user_id,user_ip) values (0,\"{$this->mTitle}\")";             
-                                       }                                       
-                               
+                                               $wgMemc->delete( "$wgDBname:newtalk:ip:$this->mTitle" );
+                                       }
                                }
                                
                                if($sql && !$user->getNewtalk()) { # only insert if real user and it's not already there
@@ -53,8 +52,6 @@ class UserTalkUpdate {
                                }
                        }
                }
-               
-       
        }
 }