3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 * @author Aaron Schulz
25 class BloomFilterTitleHasLogs
{
26 public static function mergeAndCheck(
27 BloomCache
$bcache, $domain, $virtualKey, array $status
29 $age = microtime( true ) - $status['asOfTime']; // seconds
30 $scopedLock = ( mt_rand( 1, (int)pow( 3, max( 0, 5 - $age ) ) ) == 1 )
31 ?
$bcache->getScopedLock( $virtualKey )
35 $updates = self
::merge( $bcache, $domain, $virtualKey, $status );
36 if ( isset( $updates['asOfTime'] ) ) {
37 $age = ( microtime( true ) - $updates['asOfTime'] );
44 public static function merge(
45 BloomCache
$bcache, $domain, $virtualKey, array $status
48 $dbr = wfGetDB( DB_SLAVE
, array(), $domain );
49 $res = $dbr->select( 'logging',
50 array( 'log_namespace', 'log_title', 'log_id', 'log_timestamp' ),
51 array( 'log_id > ' . $dbr->addQuotes( (int)$status['lastID'] ) ),
53 array( 'ORDER BY' => 'log_id', 'LIMIT' => $limit )
57 if ( $res->numRows() > 0 ) {
59 foreach ( $res as $row ) {
60 $members[] = "$virtualKey:{$row->log_namespace}:{$row->log_title}";
62 $lastID = $row->log_id
;
63 $lastTime = $row->log_timestamp
;
64 if ( !$bcache->add( 'shared', $members ) ) {
67 $updates['lastID'] = $lastID;
68 $updates['asOfTime'] = wfTimestamp( TS_UNIX
, $lastTime );
70 $updates['asOfTime'] = microtime( true );
73 $updates['epoch'] = $status['epoch'] ?
: microtime( true );
75 $bcache->setStatus( $virtualKey, $updates );