]> git.mxchange.org Git - friendica.git/commitdiff
Worker priority / no shadow worker
authorMichael <heluecht@pirati.ca>
Sat, 24 Oct 2020 08:05:03 +0000 (08:05 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 24 Oct 2020 08:05:03 +0000 (08:05 +0000)
mod/item.php
src/Core/Worker.php
src/Model/Item.php
src/Worker/CreateShadowEntry.php [deleted file]
static/dbstructure.config.php

index b77e725756b11f9cf1c1af41b7236dc997b90399..8744ba3b2efce992c6fac216fbfa4c685fe8dac8 100644 (file)
@@ -807,12 +807,6 @@ function item_post(App $a) {
                }
        }
 
-       // Insert an item entry for UID=0 for global entries.
-       // We now do it in the background to save some time.
-       // This is important in interactive environments like the frontend or the API.
-       // We don't fork a new process since this is done anyway with the following command
-       Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], "CreateShadowEntry", $post_id);
-
        // When we are doing some forum posting via ! we have to start the notifier manually.
        // These kind of posts don't initiate the notifier call in the item class.
        if ($only_to_forum) {
index 9af219e4760cb1b907f8e12bc7f0c1ca1bf775ae..c2fd16f24553fac6a50c96c6907e181519b297bc 100644 (file)
 namespace Friendica\Core;
 
 use Friendica\Core;
-use Friendica\Core\Process as ProcessAlias;
 use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Model\Process;
 use Friendica\Util\DateTimeFormat;
 
 /**
@@ -38,7 +36,7 @@ class Worker
        const STATE_REFETCH    = 3; // Worker had refetched jobs in the execution loop.
        const STATE_SHORT_LOOP = 4; // Worker is processing preassigned jobs, thus saving much time.
 
-       const FAST_COMMANDS = ['APDelivery', 'Delivery', 'CreateShadowEntry'];
+       const FAST_COMMANDS = ['APDelivery', 'Delivery'];
 
        const LOCK_PROCESS = 'worker_process';
        const LOCK_WORKER = 'worker';
@@ -580,7 +578,7 @@ class Worker
                        'workerqueue',
                        ['id', 'pid', 'executed', 'priority', 'parameter'],
                        ['NOT `done` AND `pid` != 0'],
-                       ['order' => ['priority', 'created']]
+                       ['order' => ['priority', 'retrial', 'created']]
                );
                self::$db_duration += (microtime(true) - $stamp);
 
@@ -850,7 +848,7 @@ class Worker
                $ids = [];
                $stamp = (float)microtime(true);
                $condition = ["`priority` = ? AND `pid` = 0 AND NOT `done` AND `next_try` < ?", $priority, DateTimeFormat::utcNow()];
-               $tasks = DBA::select('workerqueue', ['id', 'parameter'], $condition, ['limit' => $limit, 'order' => ['created']]);
+               $tasks = DBA::select('workerqueue', ['id', 'parameter'], $condition, ['limit' => $limit, 'order' => ['retrial', 'created']]);
                self::$db_duration += (microtime(true) - $stamp);
                while ($task = DBA::fetch($tasks)) {
                        $ids[] = $task['id'];
@@ -970,7 +968,7 @@ class Worker
                if ($limit > 0) {
                        $stamp = (float)microtime(true);
                        $condition = ["`pid` = 0 AND NOT `done` AND `next_try` < ?", DateTimeFormat::utcNow()];
-                       $tasks = DBA::select('workerqueue', ['id', 'parameter'], $condition, ['limit' => $limit, 'order' => ['priority', 'created']]);
+                       $tasks = DBA::select('workerqueue', ['id', 'parameter'], $condition, ['limit' => $limit, 'order' => ['priority', 'retrial', 'created']]);
                        self::$db_duration += (microtime(true) - $stamp);
 
                        while ($task = DBA::fetch($tasks)) {
@@ -1188,7 +1186,7 @@ class Worker
         *
         * next args are passed as $cmd command line
         * or: Worker::add(PRIORITY_HIGH, "Notifier", Delivery::DELETION, $drop_id);
-        * or: Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "CreateShadowEntry", $post_id);
+        * or: Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "Delivery", $post_id);
         *
         * @return boolean "false" if worker queue entry already existed or there had been an error
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
index 7b5ddf73e2d1eaeb81098bee026bd3e555088f36..aea428cd72a22f0d58bcb51997180a3df9cad507 100644 (file)
@@ -2325,7 +2325,7 @@ class Item
         * @param integer $itemid Item ID that should be added
         * @throws \Exception
         */
-       public static function addShadow($itemid)
+       private static function addShadow($itemid)
        {
                $fields = ['uid', 'private', 'moderated', 'visible', 'deleted', 'network', 'uri'];
                $condition = ['id' => $itemid, 'parent' => [0, $itemid]];
@@ -2388,7 +2388,7 @@ class Item
         * @param integer $itemid Item ID that should be added
         * @throws \Exception
         */
-       public static function addShadowPost($itemid)
+       private static function addShadowPost($itemid)
        {
                $item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $itemid]);
                if (!DBA::isResult($item)) {
@@ -2470,6 +2470,10 @@ class Item
                // Remove possibly remaining links
                $naked_body = preg_replace(Strings::autoLinkRegEx(), '', $naked_body);
 
+               if (empty($naked_body)) {
+                       return '';
+               }
+
                $ld = new Language(DI::l10n()->getAvailableLanguages());
                $languages = $ld->detect($naked_body)->limit(0, 3)->close();
                if (is_array($languages)) {
diff --git a/src/Worker/CreateShadowEntry.php b/src/Worker/CreateShadowEntry.php
deleted file mode 100644 (file)
index bd055f1..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2020, Friendica
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Worker;
-
-use Friendica\Model\Item;
-
-/**
- * This script creates posts with UID = 0 for a given public post.
- *
- * This script is started from mod/item.php to save some time when doing a post.
- */
-class CreateShadowEntry {
-       public static function execute($message_id = 0) {
-               if (empty($message_id)) {
-                       return;
-               }
-
-               Item::addShadowPost($message_id);
-       }
-}
index f8613324891b2bd101f7ddd8bd63fa096f1eb85e..3322616785b07a5cea7a619a09cf6d18397b3a9c 100755 (executable)
@@ -54,7 +54,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1370);
+       define('DB_UPDATE_VERSION', 1371);
 }
 
 return [
@@ -1460,7 +1460,7 @@ return [
                        "PRIMARY" => ["id"],
                        "done_parameter" => ["done", "parameter(64)"],
                        "done_executed" => ["done", "executed"],
-                       "done_priority_created" => ["done", "priority", "created"],
+                       "done_priority_retrial_created" => ["done", "priority", "retrial", "created"],
                        "done_priority_next_try" => ["done", "priority", "next_try"],
                        "done_pid_next_try" => ["done", "pid", "next_try"],
                        "done_pid_retrial" => ["done", "pid", "retrial"],