- $rows = $cache->getWithSetCallback(
- // Page protections always leave a new null revision
- $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
- $cache::TTL_DAY,
- function ( $curValue, &$ttl, array &$setOpts ) use ( $fname ) {
- $dbr = wfGetDB( DB_REPLICA );
-
- $setOpts += Database::getCacheSetOptions( $dbr );
-
- return iterator_to_array(
- $dbr->select(
- 'page_restrictions',
- [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
- [ 'pr_page' => $this->getArticleID() ],
- $fname
- )
- );
- }
- );
+ $loadRestrictionsFromDb = function ( Database $dbr ) use ( $fname, $id ) {
+ return iterator_to_array(
+ $dbr->select(
+ 'page_restrictions',
+ [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
+ [ 'pr_page' => $id ],
+ $fname
+ )
+ );
+ };
+
+ if ( $readLatest ) {
+ $dbr = wfGetDB( DB_MASTER );
+ $rows = $loadRestrictionsFromDb( $dbr );
+ } else {
+ $cache = ObjectCache::getMainWANInstance();
+ $rows = $cache->getWithSetCallback(
+ // Page protections always leave a new null revision
+ $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
+ $cache::TTL_DAY,
+ function ( $curValue, &$ttl, array &$setOpts ) use ( $loadRestrictionsFromDb ) {
+ $dbr = wfGetDB( DB_REPLICA );
+
+ $setOpts += Database::getCacheSetOptions( $dbr );
+
+ return $loadRestrictionsFromDb( $dbr );
+ }
+ );
+ }