1
1
Fork 0

Database performance updates

This commit is contained in:
Michael Vogel 2020-07-18 17:49:10 +02:00
parent e67dbd9747
commit 9f1d1db1ee
5 changed files with 11 additions and 13 deletions

View file

@ -136,13 +136,9 @@ function ping_init(App $a)
$notifs = ping_get_notifications(local_user());
$condition = ["`unseen` AND `uid` = ? AND `contact-id` != ? AND (`vid` != ? OR `vid` IS NULL)",
local_user(), local_user(), Verb::getID(Activity::FOLLOW)];
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid', 'wall', 'activity'];
$params = ['order' => ['received' => true]];
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
$condition = ["`unseen` AND `uid` = ? AND NOT `origin` AND (`vid` != ? OR `vid` IS NULL)",
local_user(), Verb::getID(Activity::FOLLOW)];
$items = Item::selectForUser(local_user(), ['wall'], $condition);
if (DBA::isResult($items)) {
$items_unseen = Item::inArray($items);
$arr = ['items' => $items_unseen];
@ -156,6 +152,7 @@ function ping_init(App $a)
}
}
}
DBA::close($items);
if ($network_count) {
// Find out how unseen network posts are spread across groups

View file

@ -343,7 +343,7 @@ class Database
$row['key'] . "\t" . $row['rows'] . "\t" . $row['Extra'] . "\t" .
basename($backtrace[1]["file"]) . "\t" .
$backtrace[1]["line"] . "\t" . $backtrace[2]["function"] . "\t" .
substr($query, 0, 2000) . "\n", FILE_APPEND);
substr($query, 0, 4000) . "\n", FILE_APPEND);
}
}
}
@ -712,7 +712,7 @@ class Database
@file_put_contents($this->configCache->get('system', 'db_log'), DateTimeFormat::utcNow() . "\t" . $duration . "\t" .
basename($backtrace[1]["file"]) . "\t" .
$backtrace[1]["line"] . "\t" . $backtrace[2]["function"] . "\t" .
substr($this->replaceParameters($sql, $args), 0, 2000) . "\n", FILE_APPEND);
substr($this->replaceParameters($sql, $args), 0, 4000) . "\n", FILE_APPEND);
}
}
return $retval;

View file

@ -2093,7 +2093,7 @@ class Item
DBA::close($contacts);
if (!empty($owner['alias'])) {
$condition = ['url' => $owner['alias'], 'rel' => [Contact::SHARING, Contact::FRIEND]];
$condition = ['nurl' => Strings::normaliseLink($owner['alias']), 'rel' => [Contact::SHARING, Contact::FRIEND]];
$contacts = DBA::select('contact', ['uid'], $condition);
while ($contact = DBA::fetch($contacts)) {
if ($contact['uid'] == 0) {

View file

@ -160,7 +160,6 @@ class Cron
$condition = ["`network` IN (?, ?, ?, ?) AND `uid` = ? AND NOT `self` AND `last-update` < ?",
Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, 0, $last_updated];
$total = DBA::count('contact', $condition);
$oldest_date = '';
$oldest_id = '';
$contacts = DBA::select('contact', ['id', 'last-update'], $condition, ['limit' => 100, 'order' => ['last-update']]);
@ -172,7 +171,7 @@ class Cron
Worker::add(PRIORITY_LOW, "UpdateContact", $contact['id'], 'force');
++$count;
}
Logger::info('Initiated update for public contacts', ['interval' => $count, 'total' => $total, 'id' => $oldest_id, 'oldest' => $oldest_date]);
Logger::info('Initiated update for public contacts', ['interval' => $count, 'id' => $oldest_id, 'oldest' => $oldest_date]);
DBA::close($contacts);
}

View file

@ -54,7 +54,7 @@
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1355);
define('DB_UPDATE_VERSION', 1356);
}
return [
@ -198,6 +198,7 @@ return [
"attag_uid" => ["attag(32)", "uid"],
"dfrn-id" => ["dfrn-id(64)"],
"issued-id" => ["issued-id(64)"],
"network_uid_lastupdate" => ["network", "uid", "last-update"],
"gsid" => ["gsid"]
]
],
@ -319,6 +320,7 @@ return [
"addr" => ["addr(32)"],
"alias" => ["alias(190)"],
"followers" => ["followers(190)"],
"baseurl" => ["baseurl(190)"],
"gsid" => ["gsid"]
]
],