Re-commit r34072 with some modifications:
[lhc/web/wiklou.git] / includes / LinkCache.php
index 5ce0133..f2099c8 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * Cache for article titles (prefixed DB keys) and ids linked from one source
- * 
+ *
  * @addtogroup Cache
  */
 class LinkCache {
@@ -32,10 +32,6 @@ class LinkCache {
                $this->mBadLinks = array();
        }
 
-       private function getKey( $title ) {
-               return wfMemcKey( 'lc', 'title', $title );
-       }
-
        /**
         * General accessor to get/set whether SELECT FOR UPDATE should be used
         */
@@ -50,9 +46,9 @@ class LinkCache {
                        return 0;
                }
        }
-       
+
        /**
-        * Get a field of a title object from cache. 
+        * Get a field of a title object from cache.
         * If this link is not good, it will return NULL.
         * @param Title $title
         * @param string $field ('length','redirect')
@@ -95,14 +91,10 @@ class LinkCache {
 
        public function clearBadLink( $title ) {
                unset( $this->mBadLinks[$title] );
-               $this->clearLink( $title );
        }
 
-       public function clearLink( $title ) {
-               global $wgMemc, $wgLinkCacheMemcached;
-               if( $wgLinkCacheMemcached )
-                       $wgMemc->delete( $this->getKey( $title ) );
-       }
+       /* obsolete, for old $wgLinkCacheMemcached stuff */
+       public function clearLink( $title ) {}
 
        public function getPageLinks() { return $this->mPageLinks; }
        public function getGoodLinks() { return $this->mGoodLinks; }
@@ -132,14 +124,14 @@ class LinkCache {
         * @return integer
         */
        public function addLinkObj( &$nt, $len = -1, $redirect = NULL ) {
-               global $wgMemc, $wgLinkCacheMemcached, $wgAntiLockFlags;
+               global $wgAntiLockFlags, $wgProfiler;
+
                $title = $nt->getPrefixedDBkey();
                if ( $this->isBadLink( $title ) ) { return 0; }
                $id = $this->getGoodLinkID( $title );
                if ( 0 != $id ) { return $id; }
 
                $fname = 'LinkCache::addLinkObj';
-               global $wgProfiler;
                if ( isset( $wgProfiler ) ) {
                        $fname .= ' (' . $wgProfiler->getCurrentSection() . ')';
                }
@@ -153,39 +145,29 @@ class LinkCache {
                        wfProfileOut( $fname );
                        return 0;
                }
+
                # Some fields heavily used for linking...
-               $id = NULL;
-               
-               if( $wgLinkCacheMemcached ) {
-                       $id = $wgMemc->get( $key = $this->getKey( $title ) );
-               }
-               if( !is_integer( $id ) ) {
-                       if ( $this->mForUpdate ) {
-                               $db = wfGetDB( DB_MASTER );
-                               if ( !( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) ) {
-                                       $options = array( 'FOR UPDATE' );
-                               } else {
-                                       $options = array();
-                               }
+               if ( $this->mForUpdate ) {
+                       $db = wfGetDB( DB_MASTER );
+                       if ( !( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) ) {
+                               $options = array( 'FOR UPDATE' );
                        } else {
-                               $db = wfGetDB( DB_SLAVE );
                                $options = array();
                        }
-
-                       $s = $db->selectRow( 'page', 
-                               array( 'page_id', 'page_len', 'page_is_redirect' ),
-                               array( 'page_namespace' => $ns, 'page_title' => $t ),
-                               $fname, $options );
-                       # Set fields...
-                       $id = $s ? $s->page_id : 0;
-                       $len = $s ? $s->page_len : -1;
-                       $redirect = $s ? $s->page_is_redirect : 0;
-
-                       if( $wgLinkCacheMemcached ) {
-                               $wgMemc->add( $key, $id, 3600*24 );
-                       }
+               } else {
+                       $db = wfGetDB( DB_SLAVE );
+                       $options = array();
                }
 
+               $s = $db->selectRow( 'page', 
+                       array( 'page_id', 'page_len', 'page_is_redirect' ),
+                       array( 'page_namespace' => $ns, 'page_title' => $t ),
+                       $fname, $options );
+               # Set fields...
+               $id = $s ? $s->page_id : 0;
+               $len = $s ? $s->page_len : -1;
+               $redirect = $s ? $s->page_is_redirect : 0;
+
                if( 0 == $id ) {
                        $this->addBadLinkObj( $nt );
                } else {
@@ -205,4 +187,3 @@ class LinkCache {
                $this->mBadLinks = array();
        }
 }
-