Merge pull request #14974 from annando/issue-14947
Issue 14947: Database performance improvements
This commit is contained in:
commit
07b28632ed
2 changed files with 29 additions and 6 deletions
|
|
@ -1722,19 +1722,35 @@ class Database
|
|||
*/
|
||||
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 = '';
|
||||
|
|
@ -1744,7 +1760,7 @@ class Database
|
|||
}
|
||||
$statelist .= $state . ': ' . $usage;
|
||||
}
|
||||
return (['list' => $statelist, 'amount' => $processes]);
|
||||
return (['list' => $statelist, 'amount' => $processes, 'states' => $states, 'max_time' => $max_time, 'max_query' => $max_query]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -34,6 +34,13 @@ class ExpirePosts
|
|||
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();
|
||||
|
||||
|
|
@ -133,7 +140,7 @@ class ExpirePosts
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue