]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/UpdateContacts.php
Detection of local requests
[friendica.git] / src / Worker / UpdateContacts.php
index 699e0f5abbe5e9529d2ee1ce6e25506733e3ea54..ba4f9db41c8f32482c93097f79a151bc0253dee8 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -49,24 +49,34 @@ class UpdateContacts
                        return;
                }
 
-               // Add every contact our system interacted with and hadn't been updated for a week if unarchived
-               // or for a month if archived.
-               $condition = DBA::mergeConditions($base_condition, ["(`id` IN (SELECT `author-id` FROM `post-user`) OR
-                       `id` IN (SELECT `owner-id` FROM `post-user`) OR `id` IN (SELECT `causer-id` FROM `post-user`) OR
-                       `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` < ?))",
+               $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')]);
-               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)]);
+               Logger::info('Fetched federated user contacts', ['count' => count($ids)]);
+
+               $conditions = ["`id` IN (SELECT `author-id` FROM `post-user`)", "`id` IN (SELECT `owner-id` FROM `post-user`)", 
+                       "`id` IN (SELECT `causer-id` FROM `post-user`)", "`id` IN (SELECT `cid` FROM `post-tag`)",
+                       "`id` IN (SELECT `cid` FROM `user-contact`)"];
+
+               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, $ids, $limit);
+                       Logger::info('Fetched interacting federated contacts', ['count' => count($ids), 'condition' => $contact_condition]);
+               }
+
+               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 `archive` AND `last-update` < ?))",
+                               ["(`last-update` < ? OR (NOT `failed` AND `last-update` < ?))",
                                        DateTimeFormat::utc('now - 6 month'), DateTimeFormat::utc('now - 1 month')]);
-                       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]);
@@ -91,9 +101,9 @@ class UpdateContacts
         */
        private static function getContactsToUpdate(array $condition, array $ids = [], int $limit)
        {
-               $contacts = DBA::select('contact', ['id'], $condition, ['limit' => $limit, 'order' => ['last-update']]);
+               $contacts = DBA::select('contact', ['id'], $condition, ['limit' => $limit]);
                while ($contact = DBA::fetch($contacts)) {
-                       $ids[] = $contact['id'];
+                       $ids[$contact['id']] = $contact['id'];
                }
                DBA::close($contacts);
                return $ids;