r36969 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36968‎ | r36969 | r36970 >
Date:07:49, 3 July 2008
Author:demon
Status:old
Tags:
Comment:
Cache foreign image descriptions in the transcache, saves an Http::get() on cache hit.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/filerepo/File.php (modified) (history)
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -30,7 +30,7 @@
3131 // Optional settings
3232 $this->initialCapital = true; // by default
3333 foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription',
34 - 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection' ) as $var )
 34+ 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', 'useTransCache' ) as $var )
3535 {
3636 if ( isset( $info[$var] ) ) {
3737 $this->$var = $info[$var];
Index: trunk/phase3/includes/filerepo/File.php
@@ -1067,14 +1067,54 @@
10681068 }
10691069 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName() );
10701070 if ( $renderUrl ) {
 1071+ if ( $this->repo->useTransCache ) {
 1072+ wfDebug("Attempting to get the description from the transwiki cache...");
 1073+ $this->purgeTransCacheEntries();
 1074+ $dbr = wfGetDB(DB_SLAVE);
 1075+ $obj = $dbr->selectRow('transcache', array('tc_contents'),
 1076+ array('tc_url' => $renderUrl));
 1077+ if ($obj) {
 1078+ wfDebug("success!\n");
 1079+ return $obj->tc_contents;
 1080+ }
 1081+ wfDebug("miss\n");
 1082+ }
10711083 wfDebug( "Fetching shared description from $renderUrl\n" );
1072 - return Http::get( $renderUrl );
 1084+ $res = Http::get( $renderUrl );
 1085+ if ( $res && $this->repo->useTransCache ) $this->addToTransCache( $res, $renderUrl );
 1086+ return $res;
10731087 } else {
10741088 return false;
10751089 }
10761090 }
10771091
10781092 /**
 1093+ * Purge expired transcache entries
 1094+ */
 1095+ function purgeTranscacheEntries() {
 1096+ global $wgTranscludeCacheExpiry;
 1097+ $dbw = wfGetDB( DB_MASTER );
 1098+ $table = $dbw->tableName('transcache');
 1099+ $expiry = $dbw->addQuotes(time() - $wgTranscludeCacheExpiry);
 1100+ $res = $dbw->delete( $table, array("tc_time < $expiry"), __METHOD__ );
 1101+ if ($res) wfDebug("purging old transcache entries...");
 1102+ }
 1103+
 1104+ /**
 1105+ * Add new transcache entry
 1106+ *
 1107+ * @param string $text Text to add to the cache
 1108+ * @param string $url Url we're caching
 1109+ */
 1110+ function addToTransCache( $text, $url ) {
 1111+ $dbw = wfGetDB( DB_MASTER );
 1112+ $dbw->replace('transcache', array('tc_url'), array(
 1113+ 'tc_url' => $url,
 1114+ 'tc_time' => time(),
 1115+ 'tc_contents' => $text));
 1116+ }
 1117+
 1118+ /**
10791119 * Get discription of file revision
10801120 * STUB
10811121 */
Index: trunk/phase3/RELEASE-NOTES
@@ -179,6 +179,8 @@
180180 * Added blank special page Special:BlankPage for benchmarking, etc.
181181 * (bug 13862) Specialpages now has a horizontal TOC if there's three or more
182182 groups.
 183+* Foreign repo file descriptions via fetchDescription are now cached in the
 184+ transcache.
183185
184186 === Bug fixes in 1.13 ===
185187

Status & tagging log