Index: trunk/extensions/GlobalUsage/GlobalUsageDaemon.php |
— | — | @@ -244,7 +244,13 @@ |
245 | 245 | $this->setTimestamp($wiki, $newTs); |
246 | 246 | |
247 | 247 | // Return when this function should be called again |
248 | | - return $this->incrementTimestamp($newTs, $interval); |
| 248 | + $waitUntil = wfTimestamp(TS_MW, $this->incrementTimestamp($newTs, $interval)); |
| 249 | + |
| 250 | + $res = $dbr->select('recentchanges', 'MAX(rc_timestamp) AS r', '', __METHOD__); |
| 251 | + $row = $res->fetchRow(); |
| 252 | + $res->free(); |
| 253 | + return array($waitUntil, $row['r'] > $waitUntil); |
| 254 | + |
249 | 255 | } |
250 | 256 | |
251 | 257 | /* |
— | — | @@ -280,10 +286,12 @@ |
281 | 287 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
282 | 288 | $data = unserialize(curl_exec($curl)); |
283 | 289 | curl_close($curl); |
| 290 | + if (!$data) return false; |
284 | 291 | |
285 | 292 | $this->namespaces[$wiki] = array(); |
286 | 293 | foreach ($data['query']['namespaces'] as $id => $value) |
287 | 294 | $this->namespaces[$wiki][$id] = $value['*']; |
| 295 | + return true; |
288 | 296 | } |
289 | 297 | } |
290 | 298 | |
— | — | @@ -341,13 +349,14 @@ |
342 | 350 | |
343 | 351 | // Fetch namespaces |
344 | 352 | if (!isset($this->namespaces[$wiki])) |
345 | | - $this->fetchNamespaces($wiki); |
| 353 | + if (!$this->fetchNamespaces($wiki)) |
| 354 | + die("Could not fetch namespaces for {$wiki}\n"); |
346 | 355 | $dbr = $this->getDatabase($wiki); |
347 | 356 | |
348 | 357 | while (true) { |
349 | | - $waitUntil = $this->processRecentChanges($wiki, $interval); |
| 358 | + list($waitUntil, $hasMore) = $this->processRecentChanges($wiki, $interval); |
350 | 359 | while ($waitUntil > time() - $dbr->getLag()) { |
351 | | - $sleepTime = max($waitUntil + $dbr->getLag() - time(), 0); |
| 360 | + $sleepTime = max(wfTimestamp(TS_UNIX, $waitUntil) + $dbr->getLag() - time(), 0); |
352 | 361 | $this->debug("Sleeping {$sleepTime} seconds: ". |
353 | 362 | 'need to wait until '.wfTimestamp(TS_MW, $waitUntil). |
354 | 363 | '; now is '.wfTimestamp(TS_MW)); |
— | — | @@ -369,23 +378,38 @@ |
370 | 379 | reset($waitUntil); |
371 | 380 | |
372 | 381 | $dbr = $this->getDatabase(key($waitUntil)); |
373 | | - while (current($waitUntil) > time() - $dbr->getLag()) { |
374 | | - $sleepTime = max(current($waitUntil) + $dbr->getLag() - time(), 0); |
375 | | - $this->debug("Sleeping {$sleepTime} seconds: ". |
376 | | - 'need to wait until '. |
377 | | - wfTimestamp(TS_MW, current($waitUntil)). |
378 | | - '; now is '.wfTimestamp(TS_MW)); |
379 | | - sleep($sleepTime); |
| 382 | + if (current($waitUntil) != 0) { |
| 383 | + $waitUntilTime = wfTimestamp(TS_UNIX, current($waitUntil)); |
| 384 | + $lag = $dbr->getLag(); |
| 385 | + while ($waitUntilTime > time() - $lag) { |
| 386 | + $sleepTime = max($waitUntilTime - time() + $lag, 0); |
| 387 | + $this->debug("Sleeping {$sleepTime} seconds: ". |
| 388 | + 'need to wait until '.current($waitUntil). |
| 389 | + '; now is '.wfTimestamp(TS_MW, time() - $lag)); |
| 390 | + sleep($sleepTime); |
| 391 | + } |
380 | 392 | } |
381 | 393 | |
382 | 394 | $wiki = key($waitUntil); |
383 | 395 | |
384 | 396 | // Fetch namespaces |
385 | 397 | if (!isset($this->namespaces[$wiki])) |
386 | | - $this->fetchNamespaces($wiki); |
| 398 | + if (!$this->fetchNamespaces($wiki)) { |
| 399 | + $this->debug("Could not fetch namespaces for {$wiki}"); |
| 400 | + unset($waitUntil[$wiki]); |
| 401 | + continue; |
| 402 | + } |
387 | 403 | |
388 | 404 | $this->debug("Processing recentchanges for {$wiki}"); |
389 | | - $waitUntil[$wiki] = $this->processRecentChanges($wiki, $interval); |
| 405 | + $now = time(); |
| 406 | + list($waitUntil[$wiki], $hasMore) = $this->processRecentChanges($wiki, $interval); |
| 407 | + if (!$hasMore) { |
| 408 | + // There are no more entries. Set the timestamp to *now* to avoid locking |
| 409 | + // of other wikis by rarely updated wikis |
| 410 | + $next = substr(substr(wfTimestamp(TS_MW, $now - $dbr->getLag()), |
| 411 | + 0, 14 - $interval).'00000000000000', 0, 14); |
| 412 | + $waitUntil[$wiki] = wfTimestamp(TS_MW, $this->incrementTimestamp($next, $interval)); |
| 413 | + } |
390 | 414 | } |
391 | 415 | } |
392 | 416 | } |
Index: trunk/extensions/GlobalUsage/GlobalUsage.sql |
— | — | @@ -16,5 +16,5 @@ |
17 | 17 | -- On gil_is_local change |
18 | 18 | INDEX (gil_wiki, gil_to), |
19 | 19 | -- On the special page itself |
20 | | - INDEX (gil_to, gil_is_local), |
| 20 | + INDEX (gil_to, gil_is_local) |
21 | 21 | ) /*$wgDBTableOptions*/; |
\ No newline at end of file |