Use cache set options in SqlBlobStore::getBlob
[lhc/web/wiklou.git] / includes / Storage / SqlBlobStore.php
index 0714633..ec66431 100644 (file)
@@ -35,6 +35,7 @@ use Language;
 use MWException;
 use WANObjectCache;
 use Wikimedia\Assert\Assert;
+use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
 use Wikimedia\Rdbms\LoadBalancer;
 
@@ -228,7 +229,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
                                // used. We'll need to assess expected fallout before doing that.
                        }
 
-                       $dbw = $this->getDBConnection( DB_REPLICA );
+                       $dbw = $this->getDBConnection( DB_MASTER );
 
                        $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
                        $dbw->insert(
@@ -269,7 +270,10 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
                        // TODO: change key, since this is not necessarily revision text!
                        $this->cache->makeKey( 'revisiontext', 'textid', $blobAddress ),
                        $this->getCacheTTL(),
-                       function () use ( $blobAddress, $queryFlags ) {
+                       function ( $unused, &$ttl, &$setOpts ) use ( $blobAddress, $queryFlags ) {
+                               list( $index ) = DBAccessObjectUtils::getDBOptions( $queryFlags );
+                               $setOpts += Database::getCacheSetOptions( $this->getDBConnection( $index ) );
+
                                return $this->fetchBlob( $blobAddress, $queryFlags );
                        },
                        [ 'pcGroup' => self::TEXT_CACHE_GROUP, 'pcTTL' => IExpiringStore::TTL_PROC_LONG ]
@@ -382,7 +386,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
                                return false;
                        }
 
-                       if ( $cacheKey ) {
+                       if ( $cacheKey && $this->wikiId === false ) {
                                // Make use of the wiki-local revision text cache.
                                // The cached value should be decompressed, so handle that and return here.
                                // NOTE: we rely on $this->cache being the right cache for $this->wikiId!
@@ -466,6 +470,11 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
                        return false;
                }
 
+               if ( in_array( 'error', $blobFlags ) ) {
+                       // Error row, return false
+                       return false;
+               }
+
                if ( in_array( 'gzip', $blobFlags ) ) {
                        # Deal with optional compression of archived pages.
                        # This can be done periodically via maintenance/compressOld.php, and