X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FUpdateGServers.php;h=e53754584661cd5ac04e9b8ee02cf3eaeb71f4df;hb=036b565a7846916f763ce1dcbcaade0844ff1589;hp=2200d02e9261419de97d67ac3554c1fff4fdff15;hpb=0e05ff68686270d87447c570e28543a5bcc7e755;p=friendica.git diff --git a/src/Worker/UpdateGServers.php b/src/Worker/UpdateGServers.php index 2200d02e92..e537545846 100644 --- a/src/Worker/UpdateGServers.php +++ b/src/Worker/UpdateGServers.php @@ -1,6 +1,6 @@ get('system', 'gserver_update_limit'); + if (empty($update_limit)) { return; } - $updated = 0; + $updating = Worker::countWorkersByCommand('UpdateGServer'); + $limit = $update_limit - $updating; + if ($limit <= 0) { + Logger::info('The number of currently running jobs exceed the limit'); + return; + } - while ($gserver = DBA::fetch($gservers)) { - if (!GServer::updateNeeded($gserver['created'], '', $gserver['last_failure'], $gserver['last_contact'])) { - continue; - } - Logger::info('Update server status', ['server' => $gserver['url']]); + $total = DBA::count('gserver'); + $condition = ["`next_contact` < ? AND (`nurl` != ? OR `url` != ?)", DateTimeFormat::utcNow(), '', '']; + $outdated = DBA::count('gserver', $condition); + Logger::info('Server status', ['total' => $total, 'outdated' => $outdated, 'updating' => $limit]); - Worker::add(PRIORITY_LOW, 'UpdateGServer', $gserver['url']); + $gservers = DBA::select('gserver', ['url', 'nurl'], $condition, ['limit' => $limit]); + if (!DBA::isResult($gservers)) { + return; + } - if (++$updated > 250) { - return; + $count = 0; + while ($gserver = DBA::fetch($gservers)) { + // Sometimes the "nurl" and "url" doesn't seem to fit, see https://forum.friendi.ca/display/ec054ce7-155f-c94d-6159-f50372664245 + // There are duplicated "url" but not "nurl". So we check both addresses instead of just overwriting them, + // since that would mean loosing data. + if (!empty($gserver['url'])) { + if (Worker::add(PRIORITY_LOW, 'UpdateGServer', $gserver['url'])) { + $count++; + } + } + if (!empty($gserver['nurl']) && ($gserver['nurl'] != Strings::normaliseLink($gserver['url']))) { + if (Worker::add(PRIORITY_LOW, 'UpdateGServer', $gserver['nurl'])) { + $count++; + } } } + DBA::close($gservers); + Logger::info('Updated servers', ['count' => $count]); } }