/** * Delete old records from the table, this function is called frequently to keep the table as small as possible * it's also possible to disable this function to set automatic job in cron to do that * @return int */ public static function deleteOld() { global $wgOnlineStatusBarAutoDelete; if ( !$wgOnlineStatusBarAutoDelete ) { return 0; } if ( self::getCache( 'null', 'delete' ) == 'true' ) { return 0; } // Check if we actually need to delete something before we write to master $dbr = wfGetDB( DB_SLAVE ); $time = OnlineStatusBar::getTimeoutDate(); $result = $dbr->selectField( 'online_status', 'timestamp', array( 'timestamp < ' . $dbr->addQuotes( $dbr->timestamp( $time ) ) ), __METHOD__, array( 'LIMIT 1' ) ); if ( $result === false ) { // no need for delete return 0; } // calculate time and convert it back to mediawiki format $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'online_status', array( 'timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $time ) ) ), __METHOD__ ); self::setCache( 'null', 'true', 'delete', 3600 ); // remember we deleted it for 1 hour so that we avoid calling this too many times return 0; }