<commit_before><?php

use Friendica\Core\Config;

require_once('include/queue_fn.php');
require_once('include/dfrn.php');
require_once("include/datetime.php");
require_once('include/items.php');
require_once('include/bbcode.php');
require_once('include/socgraph.php');
require_once('include/cache.php');

function queue_run(&$argv, &$argc){
	global $a;

	if ($argc > 1) {
		$queue_id = intval($argv[1]);
	} else {
		$queue_id = 0;
	}

	$cachekey_deadguy = 'queue_run:deadguy:';
	$cachekey_server = 'queue_run:server:';

	if (!$queue_id) {

		logger('queue: start');

		// Handling the pubsubhubbub requests
		proc_run(PRIORITY_HIGH,'include/pubsubpublish.php');

		$r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
			INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
			WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
		if ($r) {
			foreach ($r as $rr) {
				logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']);
				logger('Expired queue data: ' . $rr['content'], LOGGER_DATA);
			}
			q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
		}

		// For the first 12 hours we'll try to deliver every 15 minutes
		// After that, we'll only attempt delivery once per hour.

		$r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`");

		call_hooks('queue_predeliver', $a, $r);

		if (dbm::is_result($r)) {
			foreach ($r as $q_item) {
				logger('Call queue for id '.$q_item['id']);
				proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']);
			}
		}
		return;
	}


	// delivering

	require_once('include/salmon.php');
	require_once('include/diaspora.php');

	$r = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
		intval($queue_id));

	if (!dbm::is_result($r)) {
		return;
	}

	$q_item = $r[0];
<commit_msg>Don't fork a new worker<commit_after><?php

use Friendica\Core\Config;

require_once('include/queue_fn.php');
require_once('include/dfrn.php');
require_once("include/datetime.php");
require_once('include/items.php');
require_once('include/bbcode.php');
require_once('include/socgraph.php');
require_once('include/cache.php');

function queue_run(&$argv, &$argc){
	global $a;

	if ($argc > 1) {
		$queue_id = intval($argv[1]);
	} else {
		$queue_id = 0;
	}

	$cachekey_deadguy = 'queue_run:deadguy:';
	$cachekey_server = 'queue_run:server:';

	if (!$queue_id) {

		logger('queue: start');

		// Handling the pubsubhubbub requests
		proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), 'include/pubsubpublish.php');

		$r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
			INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
			WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
		if ($r) {
			foreach ($r as $rr) {
				logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']);
				logger('Expired queue data: ' . $rr['content'], LOGGER_DATA);
			}
			q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
		}

		// For the first 12 hours we'll try to deliver every 15 minutes
		// After that, we'll only attempt delivery once per hour.

		$r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`");

		call_hooks('queue_predeliver', $a, $r);

		if (dbm::is_result($r)) {
			foreach ($r as $q_item) {
				logger('Call queue for id '.$q_item['id']);
				proc_run(array('priority' => PRIORITY_LOW, 'dont_fork' => true), "include/queue.php", $q_item['id']);
			}
		}
		return;
	}


	// delivering

	require_once('include/salmon.php');
	require_once('include/diaspora.php');

	$r = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
		intval($queue_id));

	if (!dbm::is_result($r)) {
		return;
	}

	$q_item = $r[0];

{'fraction_non_alphanumeric': 0.1938446264581782, 'fraction_numerical': 0.007942417473318442, 'mean_word_length': 4.330687830687831, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7174591', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1492, 'n_words': 343}