]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/UpdateContacts.php
spelling: posts
[friendica.git] / src / Worker / UpdateContacts.php
index e6469fe19e0a1ae8dca8fbd254334abb7c6ce556..6fb71eec383fff892fea758f28e99343589372c4 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
-use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\Contact;
+use Friendica\Model\GServer;
 use Friendica\Util\DateTimeFormat;
 
 /**
@@ -55,13 +56,29 @@ class UpdateContacts
                        $condition = array_merge(['local-data' => true], $condition);
                }
 
-               $condition = array_merge(["`next-update` < ?", DateTimeFormat::utcNow()], $condition);
-               $contacts = DBA::select('contact', ['id'], $condition, ['order' => ['next-update'], 'limit' => $limit]);
+               $condition = DBA::mergeConditions(["`next-update` < ?", DateTimeFormat::utcNow()], $condition);
+               $contacts = DBA::select('contact', ['id', 'url', 'gsid', 'baseurl'], $condition, ['order' => ['next-update'], 'limit' => $limit]);
                $count = 0;
                while ($contact = DBA::fetch($contacts)) {
-                       if (Worker::add(['priority' => PRIORITY_LOW, 'dont_fork' => true], "UpdateContact", $contact['id'])) {
-                               ++$count;
+                       if (Contact::isLocal($contact['url'])) {
+                               continue;
                        }
+
+                       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]);
+                       }
+
+                       Worker::coolDown();
                }
                DBA::close($contacts);