X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FPollContacts.php;h=ba908cb8f3b1b7b01e097d70852f8462276d0887;hb=b9bb525fe91c176ada2323c2d628291a27594d59;hp=fbc1286b15f946b0f33beff7fa64a9659e47de7f;hpb=d9658f42e7b7fb6630141c3f354ed59cfe98a6d1;p=friendica.git diff --git a/src/Worker/PollContacts.php b/src/Worker/PollContacts.php index fbc1286b15..ba908cb8f3 100644 --- a/src/Worker/PollContacts.php +++ b/src/Worker/PollContacts.php @@ -1,6 +1,6 @@ get('system', 'account_abandon_days')); if ($abandon_days < 1) { $abandon_days = 0; } + $condition = ['network' => [Protocol::FEED, Protocol::MAIL, Protocol::OSTATUS], 'self' => false, 'blocked' => false, 'archive' => false]; + if (!empty($abandon_days)) { - $sql .= " AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL ? DAY"; - $parameters[] = $abandon_days; + $condition = DBA::mergeConditions($condition, + ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed` AND `last-activity` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]); + } else { + $condition = DBA::mergeConditions($condition, + ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`)", 0]); } - $contacts = DBA::p($sql, $parameters); - + $contacts = DBA::select('contact', ['id', 'nick', 'name', 'network', 'archive', 'last-update', 'priority', 'rating'], $condition); if (!DBA::isResult($contacts)) { return; } while ($contact = DBA::fetch($contacts)) { - $ratings = [0, 3, 7, 8, 9, 10]; - if (DI::config()->get('system', 'adjust_poll_frequency') && ($contact['network'] == Protocol::FEED)) { - $rating = $contact['rating']; - } elseif (array_key_exists($contact['priority'], $ratings)) { - $rating = $ratings[$contact['priority']]; - } else { - $rating = -1; - } - - // Friendica and OStatus are checked once a day - if (in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS])) { - $rating = 8; - } - - // ActivityPub is checked once a week - if ($contact['network'] == Protocol::ACTIVITYPUB) { - $rating = 9; - } - - // Check archived contacts once a month - if ($contact['archive']) { - $rating = 10; - } - - if ($rating < 0) { + $interval = Feed::getPollInterval($contact); + if ($interval == 0) { continue; } - /* - * Based on $contact['priority'], should we poll this site now? Or later? - */ - - $min_poll_interval = DI::config()->get('system', 'min_poll_interval'); - - $poll_intervals = [$min_poll_interval . ' minute', '15 minute', '30 minute', - '1 hour', '2 hour', '3 hour', '6 hour', '12 hour' ,'1 day', '1 week', '1 month']; $now = DateTimeFormat::utcNow(); - $next_update = DateTimeFormat::utc($contact['last-update'] . ' + ' . $poll_intervals[$rating]); + $next_update = DateTimeFormat::utc($contact['last-update'] . ' + ' . $interval . ' minute'); - if (empty($poll_intervals[$rating]) || ($now < $next_update)) { - Logger::debug('No update', ['cid' => $contact['id'], 'rating' => $rating, 'next' => $next_update, 'now' => $now]); + if ($now < $next_update) { + Logger::debug('No update', ['cid' => $contact['id'], 'interval' => $interval, 'next' => $next_update, 'now' => $now]); continue; } if ((($contact['network'] == Protocol::FEED) && ($contact['priority'] <= 3)) || ($contact['network'] == Protocol::MAIL)) { - $priority = PRIORITY_MEDIUM; + $priority = Worker::PRIORITY_MEDIUM; } elseif ($contact['archive']) { - $priority = PRIORITY_NEGLIGIBLE; + $priority = Worker::PRIORITY_NEGLIGIBLE; } else { - $priority = PRIORITY_LOW; + $priority = Worker::PRIORITY_LOW; } Logger::notice("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact['priority'] . " " . $contact["nick"] . " " . $contact["name"]); Worker::add(['priority' => $priority, 'dont_fork' => true, 'force_priority' => true], 'OnePoll', (int)$contact['id']); + Worker::coolDown(); } DBA::close($contacts); }