*/
public function processlist(): array
{
+ $database = trim($this->config->get('database', 'database'));
+
$ret = $this->p('SHOW PROCESSLIST');
$data = $this->toArray($ret);
$processes = 0;
+ $max_time = 0;
+ $max_query = '';
$states = [];
foreach ($data as $process) {
- $state = trim($process['State']);
+ if ($process['db'] != $database) {
+ continue;
+ }
// Filter out all non blocking processes
- if (!in_array($state, ['', 'init', 'statistics', 'updating'])) {
- ++$states[$state];
- ++$processes;
+ $state = trim($process['State']);
+ if (in_array($state, ['', 'init', 'statistics', 'updating'])) {
+ continue;
+ }
+
+ if ($process['Time'] > $max_time) {
+ $max_time = $process['Time'];
+ $max_query = $process['Info'];
+ }
+ if (!isset($states[$state])) {
+ $states[$state] = 0;
}
+ ++$states[$state];
+ ++$processes;
}
$statelist = '';
}
$statelist .= $state . ': ' . $usage;
}
- return (['list' => $statelist, 'amount' => $processes]);
+ return (['list' => $statelist, 'amount' => $processes, 'states' => $states, 'max_time' => $max_time, 'max_query' => $max_query]);
}
/**
return;
}
+ $processlist = DBA::processlist();
+ if ($processlist['max_time'] > 60) {
+ DI::logger()->warning('Processlist shows a long running query, task will be deferred.', ['time' => $processlist['max_time'], 'query' => $processlist['max_query']]);
+ Worker::defer();
+ return;
+ }
+
DI::logger()->notice('Expire posts - Delete expired origin posts');
self::deleteExpiredOriginPosts();
DI::logger()->notice('Adding missing entries');
$rows = 0;
- $userposts = DBA::select('post-user', [], ["`uri-id` not in (select `uri-id` from `post`)"]);
+ $userposts = DBA::p("SELECT `post-user`.* FROM `post-user` LEFT JOIN `post` ON `post`.`uri-id` = `post-user`.`uri-id` WHERE `post`.`uri-id` IS NULL");
while ($fields = DBA::fetch($userposts)) {
$post_fields = DI::dbaDefinition()->truncateFieldsForTable('post', $fields);
DBA::insert('post', $post_fields, Database::INSERT_IGNORE);