jenkins-bot has submitted this change and it was merged. Change subject: Add caching to Title::loadRestrictions() ......................................................................
Add caching to Title::loadRestrictions() Change-Id: Id9dac9b67cf969cddaaa8d412cb7fd033146f17d --- M includes/Title.php 1 file changed, 42 insertions(+), 42 deletions(-) Approvals: BryanDavis: Looks good to me, approved Krinkle: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/includes/Title.php b/includes/Title.php index 24bad81..8d305b7 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2849,23 +2849,6 @@ } /** - * Loads a string into mRestrictions array - * - * @param ResultWrapper $res Resource restrictions as an SQL result. - * @param string $oldFashionedRestrictions Comma-separated list of page - * restrictions from page table (pre 1.10) - */ - private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = null ) { - $rows = []; - - foreach ( $res as $row ) { - $rows[] = $row; - } - - $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions ); - } - - /** * Compiles list of active page restrictions from both page table (pre 1.10) * and page_restrictions table for this existing page. * Public for usage by LiquidThreads. @@ -2948,36 +2931,53 @@ * restrictions from page table (pre 1.10) */ public function loadRestrictions( $oldFashionedRestrictions = null ) { - if ( !$this->mRestrictionsLoaded ) { - $dbr = wfGetDB( DB_REPLICA ); - if ( $this->exists() ) { - $res = $dbr->select( - 'page_restrictions', - [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ], - [ 'pr_page' => $this->getArticleID() ], - __METHOD__ - ); + if ( $this->mRestrictionsLoaded ) { + return; + } - $this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions ); - } else { - $title_protection = $this->getTitleProtection(); + $id = $this->getArticleID(); + if ( $id ) { + $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 ) { + $dbr = wfGetDB( DB_REPLICA ); - if ( $title_protection ) { - $now = wfTimestampNow(); - $expiry = $dbr->decodeExpiry( $title_protection['expiry'] ); + $setOpts += Database::getCacheSetOptions( $dbr ); - if ( !$expiry || $expiry > $now ) { - // Apply the restrictions - $this->mRestrictionsExpiry['create'] = $expiry; - $this->mRestrictions['create'] = explode( ',', trim( $title_protection['permission'] ) ); - } else { // Get rid of the old restrictions - $this->mTitleProtection = false; - } - } else { - $this->mRestrictionsExpiry['create'] = 'infinity'; + return iterator_to_array( + $dbr->select( + 'page_restrictions', + [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ], + [ 'pr_page' => $this->getArticleID() ], + __METHOD__ + ) + ); } - $this->mRestrictionsLoaded = true; + ); + + $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions ); + } else { + $title_protection = $this->getTitleProtection(); + + if ( $title_protection ) { + $now = wfTimestampNow(); + $expiry = wfGetDB( DB_REPLICA )->decodeExpiry( $title_protection['expiry'] ); + + if ( !$expiry || $expiry > $now ) { + // Apply the restrictions + $this->mRestrictionsExpiry['create'] = $expiry; + $this->mRestrictions['create'] = + explode( ',', trim( $title_protection['permission'] ) ); + } else { // Get rid of the old restrictions + $this->mTitleProtection = false; + } + } else { + $this->mRestrictionsExpiry['create'] = 'infinity'; } + $this->mRestrictionsLoaded = true; } } -- To view, visit https://gerrit.wikimedia.org/r/308326 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id9dac9b67cf969cddaaa8d412cb7fd033146f17d Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: BryanDavis <bda...@wikimedia.org> Gerrit-Reviewer: Gilles <gdu...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits