]> git.mxchange.org Git - friendica.git/commitdiff
Issue 9015: Reducing load of remote systems
authorMichael <heluecht@pirati.ca>
Sat, 15 Aug 2020 20:05:08 +0000 (20:05 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 15 Aug 2020 20:05:08 +0000 (20:05 +0000)
src/Model/Item.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/Feed.php
src/Worker/Cron.php
src/Worker/OnePoll.php
static/defaults.config.php

index 1fc4be2f553dda1c6ada20a14eaf2fb5047895e3..a19357635b6a09f9972931d2126a22b0ee9e57d4 100644 (file)
@@ -1355,7 +1355,7 @@ class Item
         * @param array $item
         * @return boolean item is valid
         */
-       private static function isValid(array $item)
+       public static function isValid(array $item)
        {
                // When there is no content then we don't post it
                if ($item['body'].$item['title'] == '') {
@@ -1384,7 +1384,7 @@ class Item
                        }
                }
 
-               if (Contact::isBlocked($item['author-id'])) {
+               if (!empty($item['author-id']) && Contact::isBlocked($item['author-id'])) {
                        Logger::notice('Author is blocked node-wide', ['author-link' => $item['author-link'], 'item-uri' => $item['uri']]);
                        return false;
                }
@@ -1394,12 +1394,12 @@ class Item
                        return false;
                }
 
-               if (!empty($item['uid']) && Contact\User::isBlocked($item['author-id'], $item['uid'])) {
+               if (!empty($item['uid']) && !empty($item['author-id']) && Contact\User::isBlocked($item['author-id'], $item['uid'])) {
                        Logger::notice('Author is blocked by user', ['author-link' => $item['author-link'], 'uid' => $item['uid'], 'item-uri' => $item['uri']]);
                        return false;
                }
 
-               if (Contact::isBlocked($item['owner-id'])) {
+               if (!empty($item['owner-id']) && Contact::isBlocked($item['owner-id'])) {
                        Logger::notice('Owner is blocked node-wide', ['owner-link' => $item['owner-link'], 'item-uri' => $item['uri']]);
                        return false;
                }
@@ -1409,7 +1409,7 @@ class Item
                        return false;
                }
 
-               if (!empty($item['uid']) && Contact\User::isBlocked($item['owner-id'], $item['uid'])) {
+               if (!empty($item['uid']) && !empty($item['owner-id']) && Contact\User::isBlocked($item['owner-id'], $item['uid'])) {
                        Logger::notice('Owner is blocked by user', ['owner-link' => $item['owner-link'], 'uid' => $item['uid'], 'item-uri' => $item['uri']]);
                        return false;
                }
index 1ffe034d1664cbbc5f536b59c151d835322b2f7e..f1b2d3acc772046166896f52916df4638154add2 100644 (file)
@@ -1547,7 +1547,7 @@ class Transmitter
         */
        public static function isAnnounce($item)
        {
-               if ($item['verb'] == Activity::ANNOUNCE) {
+               if (!empty($item['verb']) && ($item['verb'] == Activity::ANNOUNCE)) {
                        return true;
                }
 
index 1d68ff0e2a5e3da37a18a2ecf16ad55d6aa6a022..ba0adb8347aef89c8a4c422ed9aeca102c8a3e4d 100644 (file)
@@ -35,7 +35,6 @@ use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
-use Friendica\Network\HTTPRequest;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
@@ -496,6 +495,14 @@ class Feed
                                $item["title"] = '';
                        }
 
+                       if ($dryRun) {
+                               $items[] = $item;
+                               break;
+                       } elseif (!Item::isValid($item)) {
+                               Logger::info('Feed is invalid', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]);
+                               continue;
+                       }
+
                        $preview = '';
                        if (!empty($contact["fetch_further_information"]) && ($contact["fetch_further_information"] < 3)) {
                                // Handle enclosures and treat them as preview picture
@@ -564,34 +571,29 @@ class Feed
                                }
                        }
 
-                       if ($dryRun) {
-                               $items[] = $item;
-                               break;
-                       } else {
-                               Logger::info('Stored feed', ['item' => $item]);
+                       Logger::info('Stored feed', ['item' => $item]);
 
-                               $notify = Item::isRemoteSelf($contact, $item);
+                       $notify = Item::isRemoteSelf($contact, $item);
 
-                               // Distributed items should have a well formatted URI.
-                               // Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
-                               if ($notify) {
-                                       $item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname());
-                                       unset($item['uri']);
-                                       unset($item['parent-uri']);
+                       // Distributed items should have a well formatted URI.
+                       // Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
+                       if ($notify) {
+                               $item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname());
+                               unset($item['uri']);
+                               unset($item['parent-uri']);
 
-                                       // Set the delivery priority for "remote self" to "medium"
-                                       $notify = PRIORITY_MEDIUM;
-                               }
+                               // Set the delivery priority for "remote self" to "medium"
+                               $notify = PRIORITY_MEDIUM;
+                       }
 
-                               $id = Item::insert($item, $notify);
+                       $id = Item::insert($item, $notify);
 
-                               Logger::info("Feed for contact " . $contact["url"] . " stored under id " . $id);
+                       Logger::info("Feed for contact " . $contact["url"] . " stored under id " . $id);
 
-                               if (!empty($id) && !empty($taglist)) {
-                                       $feeditem = Item::selectFirst(['uri-id'], ['id' => $id]);
-                                       foreach ($taglist as $tag) {
-                                               Tag::store($feeditem['uri-id'], Tag::HASHTAG, $tag);
-                                       }                                       
+                       if (!empty($id) && !empty($taglist)) {
+                               $feeditem = Item::selectFirst(['uri-id'], ['id' => $id]);
+                               foreach ($taglist as $tag) {
+                                       Tag::store($feeditem['uri-id'], Tag::HASHTAG, $tag);
                                }
                        }
                }
index 2c264f0746f340fa7dca50ec1973f68e91a6c91a..9ce00fb9364fc2dd51f49eceb0cfd1cf16ce9438 100644 (file)
@@ -181,7 +181,7 @@ class Cron
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        private static function pollContacts() {
-               $min_poll_interval = DI::config()->get('system', 'min_poll_interval', 1);
+               $min_poll_interval = DI::config()->get('system', 'min_poll_interval');
 
                Addon::reload();
 
index 00d5694db374cdb0ece4b580ddfbcb67457ae5c3..4dfbf7cadbb95863418c7d607f6d5c618e6d453c 100644 (file)
@@ -60,7 +60,7 @@ class OnePoll
                        return;
                }
 
-               if (($contact['network'] != Protocol::MAIL) || $force) {
+               if (($contact['network'] != Protocol::MAIL) && $force) {
                        Contact::updateFromProbe($contact_id);
                }
 
index 8111a68f1aadb4c75d54f03debf3e14fbf6d9908..5e5b48c683c53564b382b26693abdd37f6816c3b 100644 (file)
@@ -331,7 +331,7 @@ return [
 
                // min_poll_interval (Integer)
                // minimal distance in minutes between two polls for a contact. Reasonable values are between 1 and 59.
-               'min_poll_interval' => 1,
+               'min_poll_interval' => 15,
 
                // no_count (Boolean)
                // Don't do count calculations (currently only when showing photo albums).