X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FUpdateContacts.php;h=6fb71eec383fff892fea758f28e99343589372c4;hb=131695cb1167a831dbe87a0f2b1bde755dabd55f;hp=d5fe2f2079eaca828d9b6331d43efc3e37a0c41c;hpb=62be1c5614b1e100748a79f658e6b2c1148d21aa;p=friendica.git diff --git a/src/Worker/UpdateContacts.php b/src/Worker/UpdateContacts.php index d5fe2f2079..6fb71eec38 100644 --- a/src/Worker/UpdateContacts.php +++ b/src/Worker/UpdateContacts.php @@ -1,6 +1,6 @@ array_merge(Protocol::FEDERATED, [Protocol::ZOT, Protocol::PHANTOM]), 'self' => false]; - $update_limit = DI::config()->get('system', 'contact_update_limit'); if (empty($update_limit)) { return; @@ -49,66 +48,40 @@ class UpdateContacts return; } - $condition = DBA::mergeConditions($base_condition, - ["`uid` != ? AND (`last-update` < ? OR (NOT `failed` AND `last-update` < ?))", - 0, DateTimeFormat::utc('now - 1 month'), DateTimeFormat::utc('now - 1 week')]); - $ids = self::getContactsToUpdate($condition, $limit, []); - Logger::info('Fetched federated user contacts', ['count' => count($ids)]); - - $conditions = ["`id` IN (SELECT `author-id` FROM `post`)", - "`id` IN (SELECT `owner-id` FROM `post`)", - "`id` IN (SELECT `causer-id` FROM `post` WHERE NOT `causer-id` IS NULL)", - "`id` IN (SELECT `cid` FROM `post-tag`)", - "`id` IN (SELECT `cid` FROM `user-contact`)"]; + Logger::info('Updating contact', ['count' => $limit]); - foreach ($conditions as $contact_condition) { - $condition = DBA::mergeConditions($base_condition, - [$contact_condition . " AND (`last-update` < ? OR (NOT `failed` AND `last-update` < ?))", - DateTimeFormat::utc('now - 1 month'), DateTimeFormat::utc('now - 1 week')]); - $ids = self::getContactsToUpdate($condition, $limit, $ids); - Logger::info('Fetched interacting federated contacts', ['count' => count($ids), 'condition' => $contact_condition]); - } + $condition = ['self' => false]; - if (count($ids) > $limit) { - $ids = array_slice($ids, 0, $limit, true); - } - - if (!DI::config()->get('system', 'update_active_contacts')) { - // Add every contact (mostly failed ones) that hadn't been updated for six months - // and every non failed contact that hadn't been updated for a month - $condition = DBA::mergeConditions($base_condition, - ["(`last-update` < ? OR (NOT `failed` AND `last-update` < ?))", - DateTimeFormat::utc('now - 6 month'), DateTimeFormat::utc('now - 1 month')]); - $previous = count($ids); - $ids = self::getContactsToUpdate($condition, $limit - $previous, $ids); - Logger::info('Fetched federated contacts', ['count' => count($ids) - $previous]); + if (DI::config()->get('system', 'update_active_contacts')) { + $condition = array_merge(['local-data' => true], $condition); } + $condition = DBA::mergeConditions(["`next-update` < ?", DateTimeFormat::utcNow()], $condition); + $contacts = DBA::select('contact', ['id', 'url', 'gsid', 'baseurl'], $condition, ['order' => ['next-update'], 'limit' => $limit]); $count = 0; - foreach ($ids as $id) { - if (Worker::add(PRIORITY_LOW, "UpdateContact", $id)) { - ++$count; + while ($contact = DBA::fetch($contacts)) { + if (Contact::isLocal($contact['url'])) { + continue; } - } - Logger::info('Initiated update for federated contacts', ['count' => $count]); - } + try { + if ((!empty($contact['gsid']) || !empty($contact['baseurl'])) && GServer::reachable($contact)) { + $stamp = (float)microtime(true); + $success = Contact::updateFromProbe($contact['id']); + Logger::debug('Direct update', ['id' => $contact['id'], 'count' => $count, 'duration' => round((float)microtime(true) - $stamp, 3), 'success' => $success]); + ++$count; + } elseif (UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id'])) { + Logger::debug('Update by worker', ['id' => $contact['id'], 'count' => $count]); + ++$count; + } + } catch (\InvalidArgumentException $e) { + Logger::notice($e->getMessage(), ['contact' => $contact]); + } - /** - * Returns contact ids based on a given condition - * - * @param array $condition - * @param int $limit - * @param array $ids - * @return array contact ids - */ - private static function getContactsToUpdate(array $condition, int $limit, array $ids = []): array - { - $contacts = DBA::select('contact', ['id'], $condition, ['limit' => $limit]); - while ($contact = DBA::fetch($contacts)) { - $ids[$contact['id']] = $contact['id']; + Worker::coolDown(); } DBA::close($contacts); - return $ids; + + Logger::info('Initiated update for federated contacts', ['count' => $count]); } }