r67301 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67300‎ | r67301 | r67302 >
Date:22:08, 3 June 2010
Author:aaron
Status:ok
Tags:
Comment:
* Split purgeReviewablePages.php into two phases. Nice for uninstallation and not just reconfiguring.
* Follow-up r67294, r67292: actually return out for sanity check failures :)
Modified paths:
  • /trunk/extensions/FlaggedRevs/maintenance/purgeReviewablePages.inc (modified) (history)
  • /trunk/extensions/FlaggedRevs/maintenance/purgeReviewablePages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/maintenance/purgeReviewablePages.inc
@@ -1,18 +1,20 @@
22 <?php
33
4 -function purge_reviewable_pages( $db ) {
 4+function list_reviewable_pages( $db, $fileHandle ) {
55 global $wgFlaggedRevsNamespaces, $wgUseSquid, $wgUseFileCache;
6 - echo "Purging squid cache for all reviewable pages...\n";
7 - if ( !$wgUseSquid || !$wgUseFileCache ) {
8 - echo "Squid/file cache not enabled...nothing to purge.\n";
 6+ echo "Building list of all reviewable pages to purge ...\n";
 7+ if ( !$wgUseSquid && !$wgUseFileCache ) {
 8+ echo "Squid/file cache not enabled ... nothing to purge.\n";
 9+ return;
910 } elseif ( empty( $wgFlaggedRevsNamespaces ) ) {
10 - echo "There are no reviewable namespaces...nothing to purge.\n";
 11+ echo "There are no reviewable namespaces ... nothing to purge.\n";
 12+ return;
1113 }
1214 $BATCH_SIZE = 500;
1315 $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
1416 $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
1517 if ( is_null( $start ) || is_null( $end ) ) {
16 - echo "...page table seems to be empty.\n";
 18+ echo "... page table seems to be empty.\n";
1719 return;
1820 }
1921 # Do remaining chunk
@@ -21,7 +23,7 @@
2224 $blockEnd = $start + $BATCH_SIZE - 1;
2325 $count = 0;
2426 while ( $blockEnd <= $end ) {
25 - echo "...doing page_id from $blockStart to $blockEnd\n";
 27+ echo "... doing page_id from $blockStart to $blockEnd\n";
2628 $res = $db->select( 'page', '*',
2729 array(
2830 "page_id BETWEEN $blockStart AND $blockEnd",
@@ -33,15 +35,43 @@
3436 $title = Title::newFromRow( $row );
3537 $fa = FlaggedArticle::getTitleInstance( $title );
3638 if ( $fa->isReviewable( FR_MASTER ) ) {
37 - $title->purgeSquid(); // send PURGE
38 - HTMLFileCache::clearFileCache( $title ); // purge poor-mans's squid
 39+ # Need to purge this page - add to list
 40+ fwrite( $fileHandle, $title->getPrefixedDBKey() . "\n" );
3941 $count++;
4042 }
4143 }
4244 $db->freeResult( $res );
4345 $blockStart += $BATCH_SIZE - 1;
4446 $blockEnd += $BATCH_SIZE - 1;
45 - wfWaitForSlaves( 5 );
 47+ wfWaitForSlaves( 5 ); // not really needed
4648 }
47 - echo "Squid/file cache purge of all reviewable pages complete ... {$count} pages\n";
 49+ echo "List of reviewable pages to purge complete ... {$count} pages\n";
4850 }
 51+
 52+function purge_reviewable_pages( $db, $fileHandle ) {
 53+ global $wgUseSquid, $wgUseFileCache;
 54+ echo "Purging squid cache for list of pages to purge ...\n";
 55+ if ( !$wgUseSquid && !$wgUseFileCache ) {
 56+ echo "Squid/file cache not enabled ... nothing to purge.\n";
 57+ return;
 58+ }
 59+ $BATCH_SIZE = 500;
 60+ $count = 0;
 61+ while ( !feof( $fileHandle ) ) {
 62+ $dbKey = trim( fgets( $fileHandle ) );
 63+ if ( $dbKey == '' ) continue; // last line?
 64+ $title = Title::newFromDBkey( $dbKey );
 65+ if ( $title ) {
 66+ $title->purgeSquid(); // send PURGE
 67+ HTMLFileCache::clearFileCache( $title ); // purge poor-mans's squid
 68+ $count++;
 69+ echo "... $dbKey\n";
 70+ if ( $count % $BATCH_SIZE ) {
 71+ wfWaitForSlaves( 5 ); // not really needed
 72+ }
 73+ } else {
 74+ echo "Invalid title - cannot purge: $dbKey\n";
 75+ }
 76+ }
 77+ echo "Squid/file cache purge of page list complete ... {$count} pages\n";
 78+}
Index: trunk/extensions/FlaggedRevs/maintenance/purgeReviewablePages.php
@@ -8,20 +8,48 @@
99 require "$IP/maintenance/commandLine.inc";
1010 require dirname(__FILE__) . '/purgeReviewablePages.inc';
1111
12 -if( isset( $options['help'] ) ) {
 12+$makeList = isset( $options['makelist'] );
 13+$purgeList = isset( $options['purgelist'] );
 14+
 15+if ( isset( $options['help'] ) || ( !$makeList && !$purgeList ) ) {
1316 echo <<<TEXT
1417 Purpose:
15 - Purge squid/file cache for all reviewable pages
 18+ Use to purge squid/file cache for all reviewable pages
1619 Usage:
1720 php purgeReviewablePages.php --help
 21+ php purgeReviewablePages.php --makelist
 22+ php purgeReviewablePages.php --purgelist
1823
19 - --help : This help message
 24+ --help : This help message
 25+ --makelist : Build the list of reviewable pages to pagesToPurge.list
 26+ --purgelist : Purge the list of pages in pagesToPurge.list
2027
2128 TEXT;
22 - exit(0);
 29+ exit( 0 );
2330 }
2431
2532 error_reporting( E_ALL );
2633
27 -$db = wfGetDB( DB_MASTER );
28 -purge_reviewable_pages( $db );
 34+$fileName = "pagesToPurge.list";
 35+
 36+if ( $makeList ) {
 37+ $db = wfGetDB( DB_MASTER );
 38+ $fileHandle = fopen( $fileName, 'w+' );
 39+ if ( !$fileHandle ) {
 40+ echo "Can't open file to create purge list.\n";
 41+ exit( -1 );
 42+ }
 43+ list_reviewable_pages( $db, $fileHandle );
 44+ fclose( $fileHandle );
 45+}
 46+
 47+if ( $purgeList ) {
 48+ $db = wfGetDB( DB_MASTER );
 49+ $fileHandle = fopen( $fileName, 'r' );
 50+ if ( !$fileHandle ) {
 51+ echo "Can't open file to read purge list.\n";
 52+ exit( -1 );
 53+ }
 54+ purge_reviewable_pages( $db, $fileHandle );
 55+ fclose( $fileHandle );
 56+}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r67292Added script to clear squid/file cache (useful for removal/uninstallation)aaron18:49, 3 June 2010
r67294Sanity check $wgFlaggedRevsNamespacesaaron19:12, 3 June 2010

Status & tagging log