Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/283238
Change subject: Allow description text caching for ForeignDBFile
......................................................................
Allow description text caching for ForeignDBFile
A large amount of real time is spent in fetching Commons
descriptions pages from wikipedias, according to xenon
flame graphs.
Change-Id: I3935bf8bf23da58b734f897d7a1979e9b2f7e5c8
---
M includes/filerepo/file/ForeignDBFile.php
1 file changed, 53 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/38/283238/1
diff --git a/includes/filerepo/file/ForeignDBFile.php
b/includes/filerepo/file/ForeignDBFile.php
index f38248b..cf0045e 100644
--- a/includes/filerepo/file/ForeignDBFile.php
+++ b/includes/filerepo/file/ForeignDBFile.php
@@ -124,8 +124,51 @@
* @return string
*/
function getDescriptionText( $lang = false ) {
- // Restore remote behavior
- return File::getDescriptionText( $lang );
+ global $wgLang;
+
+ if ( !$this->repo->fetchDescription ) {
+ return false;
+ }
+
+ $lang = $lang ?: $wgLang;
+ $renderUrl = $this->repo->getDescriptionRenderUrl(
$this->getName(), $lang->getCode() );
+ if ( !$renderUrl ) {
+ return false;
+ }
+
+ $touched = $this->repo->getSlaveDB()->selectField(
+ 'page',
+ 'page_touched',
+ [
+ 'page_namespace' => NS_FILE,
+ 'page_title' => $this->title->getDBkey()
+ ]
+ );
+ if ( $touched === false ) {
+ return false; // no description page
+ }
+
+ $cache = ObjectCache::getMainWANInstance();
+
+ return $cache->getWithSetCallback(
+ $this->repo->getLocalCacheKey(
+ 'RemoteFileDescription',
+ 'url',
+ $lang->getCode(),
+ $this->getName(),
+ $touched
+ ),
+ $this->repo->descriptionCacheExpiry ?:
$cache::TTL_UNCACHEABLE,
+ function ( $oldValue, &$ttl, array &$setOpts ) use (
$renderUrl ) {
+ wfDebug( "Fetching shared description from
$renderUrl\n" );
+ $res = Http::get( $renderUrl, [], __METHOD__ );
+ if ( !$res ) {
+ $ttl = WANObjectCache::TTL_UNCACHEABLE;
+ }
+
+ return $res;
+ }
+ );
}
/**
@@ -137,10 +180,14 @@
*/
public function getDescriptionShortUrl() {
$dbr = $this->repo->getSlaveDB();
- $pageId = $dbr->selectField( 'page', 'page_id', [
- 'page_namespace' => NS_FILE,
- 'page_title' => $this->title->getDBkey()
- ] );
+ $pageId = $dbr->selectField(
+ 'page',
+ 'page_id',
+ [
+ 'page_namespace' => NS_FILE,
+ 'page_title' => $this->title->getDBkey()
+ ]
+ );
if ( $pageId !== false ) {
$url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
--
To view, visit https://gerrit.wikimedia.org/r/283238
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3935bf8bf23da58b734f897d7a1979e9b2f7e5c8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits