From 9f1d1db1ee305f2b31e6b1572e0afbf2c76c52e8 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 18 Jul 2020 17:49:10 +0200 Subject: [PATCH] Database performance updates --- mod/ping.php | 11 ++++------- src/Database/Database.php | 4 ++-- src/Model/Item.php | 2 +- src/Worker/Cron.php | 3 +-- static/dbstructure.config.php | 4 +++- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/mod/ping.php b/mod/ping.php index d1983e8036..4b972369c7 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -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 diff --git a/src/Database/Database.php b/src/Database/Database.php index eaf4900509..5ef4815563 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -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; diff --git a/src/Model/Item.php b/src/Model/Item.php index 332c734fa5..c75286b25c 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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) { diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index a47193334c..6749b9648d 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -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); } diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index bab158d036..344a21fc5d 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -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"] ] ],