r2084 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r2083‎ | r2084 | r2085 >
Date:19:53, 27 November 2003
Author:e23
Status:old
Tags:
Comment:
Added versioning to serialized LinkCache objects. Added pref.
Modified paths:
  • /trunk/phase3/includes/LinkCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LinkCache.php
@@ -6,7 +6,10 @@
77 define ('LINKCACHE_BAD', 1);
88 define ('LINKCACHE_IMAGE', 2);
99
10 -class LinkCache {
 10+class LinkCache {
 11+ // Increment $mClassVer whenever old serialized versions of this class
 12+ // becomes incompatible with the new version.
 13+ /* private */ var $mClassVer = 1;
1114
1215 /* private */ var $mGoodLinks, $mBadLinks, $mActive;
1316 /* private */ var $mImageLinks;
@@ -140,7 +143,7 @@
141144
142145 function preFill( &$fromtitle )
143146 {
144 - global $wgEnablePersistentLC;
 147+ global $wgEnablePersistentLC, $wgCompressedPersistentLC;
145148
146149 $fname = "LinkCache::preFill";
147150 wfProfileIn( $fname );
@@ -148,12 +151,8 @@
149152 $dbkeyfrom = wfStrencode( $fromtitle->getPrefixedDBKey() );
150153
151154 if ( $wgEnablePersistentLC ) {
152 - $res = wfQuery("SELECT lcc_cacheobj FROM linkscc WHERE lcc_title = '{$dbkeyfrom}'",
153 - DB_READ);
154 - $row = wfFetchObject( $res );
155 - if( $row != FALSE){
156 - $cacheobj = gzuncompress( $row->lcc_cacheobj );
157 - $cc = unserialize( $cacheobj );
 155+ $cc =& $this->getFromLinkscc( $dbkeyfrom );
 156+ if( $cc != FALSE ){
158157 $this->mOldGoodLinks = $this->mGoodLinks = $cc->mGoodLinks;
159158 $this->mOldBadLinks = $this->mBadLinks = $cc->mBadLinks;
160159 $this->mPreFilled = true;
@@ -192,8 +191,12 @@
193192
194193 if ( $wgEnablePersistentLC ) {
195194 // put fetched link data into cache
196 - $serCachegz = wfStrencode( gzcompress( serialize( $this ), 3) );
197 - wfQuery("REPLACE INTO linkscc VALUES({$id}, '{$dbkeyfrom}', '{$serCachegz}')",
 195+ if( $wgCompressedPersistentLC and function_exists( "gzcompress" ) ) {
 196+ $ser = wfStrencode( gzcompress( serialize( $this ), 3 ));
 197+ } else {
 198+ $ser = wfStrencode( serialize( $this ) );
 199+ }
 200+ wfQuery("REPLACE INTO linkscc VALUES({$id}, '{$dbkeyfrom}', '{$ser}')",
198201 DB_WRITE);
199202 wfDebug( "LinkCache::preFill - saved to linkscc\n" );
200203 }
@@ -270,6 +273,28 @@
271274 $this->mBadLinks = array();
272275 $this->mImageLinks = array();
273276 }
274 -
 277+
 278+
 279+ function &getFromLinkscc( $dbkeyfrom ){
 280+ $res = wfQuery("SELECT lcc_cacheobj FROM linkscc WHERE lcc_title = '{$dbkeyfrom}'",
 281+ DB_READ);
 282+ $row = wfFetchObject( $res );
 283+ if( $row == FALSE)
 284+ return false;
 285+
 286+ $cacheobj = false;
 287+ if( function_exists( "gzuncompress" ) )
 288+ $cacheobj = @gzuncompress( $row->lcc_cacheobj );
 289+
 290+ if($cacheobj == FALSE){
 291+ $cacheobj = $row->lcc_cacheobj;
 292+ }
 293+ $cc = @unserialize( $cacheobj );
 294+ if( isset( $cc->mClassVer ) and ($cc->mClassVer == $this->mClassVer ) ){
 295+ return $cc;
 296+ } else {
 297+ return FALSE;
 298+ }
 299+ }
275300 }
276301 ?>

Status & tagging log