X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHistoryBlob.php;h=587588552ddf3403a2f664eeeffb8b79acdfeb4e;hb=b7db9837bf4fc1ec1ecf6bc5a030b2d59f522878;hp=2fe5d1f5d0dda0ab8b7e6ec98e005202bd29253b;hpb=4de24de85f25c9cbb9d078f16d2df021a8c0cff1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/HistoryBlob.php b/includes/HistoryBlob.php index 2fe5d1f5d0..587588552d 100644 --- a/includes/HistoryBlob.php +++ b/includes/HistoryBlob.php @@ -167,11 +167,22 @@ class ConcatenatedGzipHistoryBlob extends HistoryBlob } } + +/** + * One-step cache variable to hold base blobs; operations that + * pull multiple revisions may often pull multiple times from + * the same blob. By keeping the last-used one open, we avoid + * redundant unserialization and decompression overhead. + */ +global $wgBlobCache; +$wgBlobCache = array(); + + /** * @package MediaWiki */ class HistoryBlobStub { - var $mOldId, $mHash; + var $mOldId, $mHash, $mRef; /** @todo document */ function HistoryBlobStub( $hash = '', $oldid = 0 ) { @@ -186,29 +197,64 @@ class HistoryBlobStub { $this->mOldId = $id; } + /** + * Sets the location (old_id) of the referring object + */ + function setReferrer( $id ) { + $this->mRef = $id; + } + + /** + * Gets the location of the referring object + */ + function getReferrer() { + return $this->mRef; + } + /** @todo document */ function getText() { - $dbr =& wfGetDB( DB_SLAVE ); - $row = $dbr->selectRow( 'text', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId ) ); - if( !$row ) { - return false; - } - $flags = explode( ',', $row->old_flags ); - if( !in_array( 'object', $flags ) ) { - return false; - } - - if( in_array( 'gzip', $flags ) ) { - // This shouldn't happen, but a bug in the compress script - // may at times gzip-compress a HistoryBlob object row. - $obj = unserialize( gzinflate( $row->old_text ) ); + global $wgBlobCache; + if( isset( $wgBlobCache[$this->mOldId] ) ) { + $obj = $wgBlobCache[$this->mOldId]; } else { - $obj = unserialize( $row->old_text ); - } - - if( !is_object( $obj ) ) { - // Correct for old double-serialization bug. - $obj = unserialize( $obj ); + $dbr =& wfGetDB( DB_SLAVE ); + $row = $dbr->selectRow( 'text', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId ) ); + if( !$row ) { + return false; + } + $flags = explode( ',', $row->old_flags ); + if( in_array( 'external', $flags ) ) { + $url=$row->old_text; + @list($proto,$path)=explode('://',$url,2); + if ($path=="") { + wfProfileOut( $fname ); + return false; + } + require_once('ExternalStore.php'); + $row->old_text=ExternalStore::fetchFromUrl($url); + + } + if( !in_array( 'object', $flags ) ) { + return false; + } + + if( in_array( 'gzip', $flags ) ) { + // This shouldn't happen, but a bug in the compress script + // may at times gzip-compress a HistoryBlob object row. + $obj = unserialize( gzinflate( $row->old_text ) ); + } else { + $obj = unserialize( $row->old_text ); + } + + if( !is_object( $obj ) ) { + // Correct for old double-serialization bug. + $obj = unserialize( $obj ); + } + + // Save this item for reference; if pulling many + // items in a row we'll likely use it again. + $obj->uncompress(); + $wgBlobCache = array( $this->mOldId => $obj ); } return $obj->getItem( $this->mHash ); } @@ -218,4 +264,44 @@ class HistoryBlobStub { return $this->mHash; } } + + +/** + * To speed up conversion from 1.4 to 1.5 schema, text rows can refer to the + * leftover cur table as the backend. This avoids expensively copying hundreds + * of megabytes of data during the conversion downtime. + * + * Serialized HistoryBlobCurStub objects will be inserted into the text table + * on conversion if $wgFastSchemaUpgrades is set to true. + * + * @package MediaWiki + */ +class HistoryBlobCurStub { + var $mCurId; + + /** @todo document */ + function HistoryBlobCurStub( $curid = 0 ) { + $this->mCurId = $curid; + } + + /** + * Sets the location (cur_id) of the main object to which this object + * points + */ + function setLocation( $id ) { + $this->mCurId = $id; + } + + /** @todo document */ + function getText() { + $dbr =& wfGetDB( DB_SLAVE ); + $row = $dbr->selectRow( 'cur', array( 'cur_text' ), array( 'cur_id' => $this->mCurId ) ); + if( !$row ) { + return false; + } + return $row->cur_text; + } +} + + ?>