Index: trunk/phase3/includes/WikiPage.php |
— | — | @@ -350,19 +350,28 @@ |
351 | 351 | * A DB query result object or... |
352 | 352 | * "fromdb" to get from a slave DB or... |
353 | 353 | * "fromdbmaster" to get from the master DB |
| 354 | + * @return void |
354 | 355 | */ |
355 | 356 | public function loadPageData( $data = 'fromdb' ) { |
356 | | - if ( $data === 'fromdb' || $data === 'fromdbmaster' ) { |
357 | | - $db = ( $data == 'fromdbmaster' ) |
358 | | - ? wfGetDB( DB_MASTER ) |
359 | | - : wfGetDB( DB_SLAVE ); |
360 | | - $data = $this->pageDataFromTitle( $db, $this->mTitle ); |
| 357 | + if ( $data === 'fromdbmaster' ) { |
| 358 | + $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle ); |
| 359 | + } elseif ( $data === 'fromdb' ) { // slave |
| 360 | + $data = $this->pageDataFromTitle( wfGetDB( DB_SLAVE ), $this->mTitle ); |
| 361 | + # Use a "last rev inserted" timestamp key to dimish the issue of slave lag. |
| 362 | + # Note that DB also stores the master position in the session and checks it. |
| 363 | + $touched = $this->getCachedLastEditTime(); |
| 364 | + if ( $touched ) { // key set |
| 365 | + if ( !$data || $touched > wfTimestamp( TS_MW, $data->page_touched ) ) { |
| 366 | + $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle ); |
| 367 | + } |
| 368 | + } |
361 | 369 | } |
362 | 370 | |
363 | 371 | $lc = LinkCache::singleton(); |
364 | 372 | |
365 | 373 | if ( $data ) { |
366 | | - $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect, $data->page_latest ); |
| 374 | + $lc->addGoodLinkObj( $data->page_id, $this->mTitle, |
| 375 | + $data->page_len, $data->page_is_redirect, $data->page_latest ); |
367 | 376 | |
368 | 377 | $this->mTitle->loadFromRow( $data ); |
369 | 378 | |
— | — | @@ -814,10 +823,11 @@ |
815 | 824 | $conditions['page_latest'] = $lastRevision; |
816 | 825 | } |
817 | 826 | |
| 827 | + $now = wfTimestampNow(); |
818 | 828 | $dbw->update( 'page', |
819 | 829 | array( /* SET */ |
820 | 830 | 'page_latest' => $revision->getId(), |
821 | | - 'page_touched' => $dbw->timestamp(), |
| 831 | + 'page_touched' => $dbw->timestamp( $now ), |
822 | 832 | 'page_is_new' => ( $lastRevision === 0 ) ? 1 : 0, |
823 | 833 | 'page_is_redirect' => $rt !== null ? 1 : 0, |
824 | 834 | 'page_len' => strlen( $text ), |
— | — | @@ -828,6 +838,7 @@ |
829 | 839 | $result = $dbw->affectedRows() != 0; |
830 | 840 | if ( $result ) { |
831 | 841 | $this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect ); |
| 842 | + $this->setCachedLastEditTime( $now ); |
832 | 843 | } |
833 | 844 | |
834 | 845 | wfProfileOut( __METHOD__ ); |
— | — | @@ -835,6 +846,27 @@ |
836 | 847 | } |
837 | 848 | |
838 | 849 | /** |
| 850 | + * Get the cached timestamp for the last time the page changed |
| 851 | + * @return string MW timestamp |
| 852 | + */ |
| 853 | + protected function getCachedLastEditTime() { |
| 854 | + global $wgMemc; |
| 855 | + $key = wfMemcKey( 'page-lastedit', md5( $this->mTitle->getPrefixedDBkey() ) ); |
| 856 | + return $wgMemc->get( $key ); |
| 857 | + } |
| 858 | + |
| 859 | + /** |
| 860 | + * Set the cached timestamp for the last time the page changed |
| 861 | + * @param $timestamp string |
| 862 | + * @return void |
| 863 | + */ |
| 864 | + protected function setCachedLastEditTime( $timestamp ) { |
| 865 | + global $wgMemc; |
| 866 | + $key = wfMemcKey( 'page-lastedit', md5( $this->mTitle->getPrefixedDBkey() ) ); |
| 867 | + $wgMemc->set( $key, wfTimestamp( TS_MW, $timestamp ), 60*15 ); |
| 868 | + } |
| 869 | + |
| 870 | + /** |
839 | 871 | * Add row to the redirect table if this is a redirect, remove otherwise. |
840 | 872 | * |
841 | 873 | * @param $dbw DatabaseBase |