Merge pull request #9450 from annando/no-shadow

Worker priority / no shadow worker
This commit is contained in:
Hypolite Petovan 2020-10-24 08:53:42 -04:00 committed by GitHub
commit c154efb028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 56 deletions

View 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. // 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. // These kind of posts don't initiate the notifier call in the item class.
if ($only_to_forum) { if ($only_to_forum) {

View File

@ -22,10 +22,8 @@
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\Core; use Friendica\Core;
use Friendica\Core\Process as ProcessAlias;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Process;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
/** /**
@ -38,7 +36,7 @@ class Worker
const STATE_REFETCH = 3; // Worker had refetched jobs in the execution loop. 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 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_PROCESS = 'worker_process';
const LOCK_WORKER = 'worker'; const LOCK_WORKER = 'worker';
@ -580,7 +578,7 @@ class Worker
'workerqueue', 'workerqueue',
['id', 'pid', 'executed', 'priority', 'parameter'], ['id', 'pid', 'executed', 'priority', 'parameter'],
['NOT `done` AND `pid` != 0'], ['NOT `done` AND `pid` != 0'],
['order' => ['priority', 'created']] ['order' => ['priority', 'retrial', 'created']]
); );
self::$db_duration += (microtime(true) - $stamp); self::$db_duration += (microtime(true) - $stamp);
@ -850,7 +848,7 @@ class Worker
$ids = []; $ids = [];
$stamp = (float)microtime(true); $stamp = (float)microtime(true);
$condition = ["`priority` = ? AND `pid` = 0 AND NOT `done` AND `next_try` < ?", $priority, DateTimeFormat::utcNow()]; $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); self::$db_duration += (microtime(true) - $stamp);
while ($task = DBA::fetch($tasks)) { while ($task = DBA::fetch($tasks)) {
$ids[] = $task['id']; $ids[] = $task['id'];
@ -970,7 +968,7 @@ class Worker
if ($limit > 0) { if ($limit > 0) {
$stamp = (float)microtime(true); $stamp = (float)microtime(true);
$condition = ["`pid` = 0 AND NOT `done` AND `next_try` < ?", DateTimeFormat::utcNow()]; $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); self::$db_duration += (microtime(true) - $stamp);
while ($task = DBA::fetch($tasks)) { while ($task = DBA::fetch($tasks)) {
@ -1188,7 +1186,7 @@ class Worker
* *
* next args are passed as $cmd command line * next args are passed as $cmd command line
* or: Worker::add(PRIORITY_HIGH, "Notifier", Delivery::DELETION, $drop_id); * 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 * @return boolean "false" if worker queue entry already existed or there had been an error
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException

View File

@ -2325,7 +2325,7 @@ class Item
* @param integer $itemid Item ID that should be added * @param integer $itemid Item ID that should be added
* @throws \Exception * @throws \Exception
*/ */
public static function addShadow($itemid) private static function addShadow($itemid)
{ {
$fields = ['uid', 'private', 'moderated', 'visible', 'deleted', 'network', 'uri']; $fields = ['uid', 'private', 'moderated', 'visible', 'deleted', 'network', 'uri'];
$condition = ['id' => $itemid, 'parent' => [0, $itemid]]; $condition = ['id' => $itemid, 'parent' => [0, $itemid]];
@ -2388,7 +2388,7 @@ class Item
* @param integer $itemid Item ID that should be added * @param integer $itemid Item ID that should be added
* @throws \Exception * @throws \Exception
*/ */
public static function addShadowPost($itemid) private static function addShadowPost($itemid)
{ {
$item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $itemid]); $item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $itemid]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
@ -2470,6 +2470,10 @@ class Item
// Remove possibly remaining links // Remove possibly remaining links
$naked_body = preg_replace(Strings::autoLinkRegEx(), '', $naked_body); $naked_body = preg_replace(Strings::autoLinkRegEx(), '', $naked_body);
if (empty($naked_body)) {
return '';
}
$ld = new Language(DI::l10n()->getAvailableLanguages()); $ld = new Language(DI::l10n()->getAvailableLanguages());
$languages = $ld->detect($naked_body)->limit(0, 3)->close(); $languages = $ld->detect($naked_body)->limit(0, 3)->close();
if (is_array($languages)) { if (is_array($languages)) {

View File

@ -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);
}
}

View File

@ -54,7 +54,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1370); define('DB_UPDATE_VERSION', 1371);
} }
return [ return [
@ -1460,7 +1460,7 @@ return [
"PRIMARY" => ["id"], "PRIMARY" => ["id"],
"done_parameter" => ["done", "parameter(64)"], "done_parameter" => ["done", "parameter(64)"],
"done_executed" => ["done", "executed"], "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_priority_next_try" => ["done", "priority", "next_try"],
"done_pid_next_try" => ["done", "pid", "next_try"], "done_pid_next_try" => ["done", "pid", "next_try"],
"done_pid_retrial" => ["done", "pid", "retrial"], "done_pid_retrial" => ["done", "pid", "retrial"],