- if (DI::config()->get('system', 'update_active_contacts')) {
- $condition = DBA::mergeConditions($condition, ["(`id` IN (SELECT `author-id` FROM `item`) OR
+ $existing = Worker::countWorkersByCommand('UpdateContact');
+ Logger::info('Already existing jobs', ['existing' => $existing]);
+ if ($existing > 100) {
+ return;
+ }
+
+ $limit = 100 - $existing;
+
+ if (!DI::config()->get('system', 'update_active_contacts')) {
+ $part = 3;
+ // Add every contact (mostly failed ones) that hadn't been updated for six months
+ $condition = DBA::mergeConditions($base_condition,
+ ["`last-update` < ?", DateTimeFormat::utc('now - 6 month')]);
+ $ids = self::getContactsToUpdate($condition, $ids, round($limit / $part));
+
+ // Add every non failed contact that hadn't been updated for a month
+ $condition = DBA::mergeConditions($base_condition,
+ ["NOT `failed` AND `last-update` < ?", DateTimeFormat::utc('now - 1 month')]);
+ $ids = self::getContactsToUpdate($condition, $ids, round($limit / $part));
+ } else {
+ $part = 1;
+ }
+
+ // Add every contact our system interacted with and hadn't been updated for a week
+ $condition = DBA::mergeConditions($base_condition, ["(`id` IN (SELECT `author-id` FROM `item`) OR