]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/PollContacts.php
Detection of local requests
[friendica.git] / src / Worker / PollContacts.php
index e73801f2b6ec42728d2732d960f1d4f61ed1b6ba..da4ac21420449f49d189667bfed366ed6e859903 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
  *
 
 namespace Friendica\Worker;
 
-use Friendica\Core\Addon;
 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\Protocol\Feed;
 use Friendica\Util\DateTimeFormat;
 
 /**
@@ -37,81 +36,37 @@ class PollContacts
 {
        public static function execute()
        {
-               Addon::reload();
-
-               $sql = "SELECT `contact`.`id`, `contact`.`nick`, `contact`.`name`, `contact`.`network`, `contact`.`archive`,
-                                       `contact`.`last-update`, `contact`.`priority`, `contact`.`rating`, `contact`.`rel`, `contact`.`subhub`
-                               FROM `user`
-                               STRAIGHT_JOIN `contact`
-                               ON `contact`.`uid` = `user`.`uid` AND `contact`.`poll` != ''
-                                       AND `contact`.`network` IN (?, ?, ?, ?, ?)
-                                       AND NOT `contact`.`self` AND NOT `contact`.`blocked`
-                                       AND `contact`.`rel` != ?
-                               WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed`";
-
-               $parameters = [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Contact::FOLLOWER];
-
-               // Only poll from those with suitable relationships,
-               // and which have a polling address and ignore Diaspora since
-               // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
                $abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
                if ($abandon_days < 1) {
                        $abandon_days = 0;
                }
 
+               $condition = ['network' => [Protocol::FEED, Protocol::MAIL, Protocol::OSTATUS], 'self' => false, 'blocked' => 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 `login_date` > UTC_TIMESTAMP() - INTERVAL ? DAY)", 0, $abandon_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;
                        }