]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/UpdateContacts.php
version 2021.03-dev
[friendica.git] / src / Worker / UpdateContacts.php
index 2328c7c84ab39bf38272d06a191fdd1385b88dde..c1f38a3b43b976b68d04ed4f016176b6cac29ba3 100644 (file)
@@ -35,8 +35,6 @@ class UpdateContacts
 {
        public static function execute()
        {
-               $count = 0;
-               $ids = [];
                $base_condition = ['network' => array_merge(Protocol::FEDERATED, [Protocol::ZOT, Protocol::PHANTOM]), 'self' => false];
 
                $update_limit = DI::config()->get('system', 'contact_update_limit');
@@ -58,8 +56,8 @@ class UpdateContacts
                        `id` IN (SELECT `cid` FROM `post-tag`) OR `id` IN (SELECT `cid` FROM `user-contact`) OR `uid` != ?) AND
                        (`last-update` < ? OR (NOT `archive` AND `last-update` < ?))",
                        0, DateTimeFormat::utc('now - 1 month'), DateTimeFormat::utc('now - 1 week')]);
-               $ids = self::getContactsToUpdate($condition, $ids, $limit - count($ids));
-
+               Logger::info('Updatable interacting federated contacts', ['count' => DBA::count('contact', $condition)]);
+               $ids = self::getContactsToUpdate($condition, [], $limit);
                Logger::info('Fetched interacting federated contacts', ['count' => count($ids)]);
 
                if (!DI::config()->get('system', 'update_active_contacts')) {
@@ -68,12 +66,17 @@ class UpdateContacts
                        $condition = DBA::mergeConditions($base_condition,
                                ["(`last-update` < ? OR (NOT `archive` AND `last-update` < ?))",
                                        DateTimeFormat::utc('now - 6 month'), DateTimeFormat::utc('now - 1 month')]);
-                       $ids = self::getContactsToUpdate($condition, $ids, $limit - count($ids));
+                       Logger::info('Updatable federated contacts', ['count' => DBA::count('contact', $condition)]);
+                       $previous = count($ids);
+                       $ids = self::getContactsToUpdate($condition, $ids, $limit - $previous);
+                       Logger::info('Fetched federated contacts', ['count' => count($ids) - $previous]);
                }
 
+               $count = 0;
                foreach ($ids as $id) {
-                       Worker::add(PRIORITY_LOW, "UpdateContact", $id);
-                       ++$count;
+                       if (Worker::add(PRIORITY_LOW, "UpdateContact", $id)) {
+                               ++$count;
+                       }
                }
 
                Logger::info('Initiated update for federated contacts', ['count' => $count]);