From 63ebbb8a16bca1cebbcb0cb4a65d1750ab67052c Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 23 Apr 2020 06:19:44 +0000 Subject: [PATCH 01/30] We now can define views --- database.sql | 45 ++++++++++- src/Database/DBStructure.php | 4 + src/Database/DBView.php | 138 ++++++++++++++++++++++++++++++++++ static/dbstructure.config.php | 2 +- static/dbview.config.php | 56 ++++++++++++++ 5 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 src/Database/DBView.php create mode 100755 static/dbview.config.php diff --git a/database.sql b/database.sql index d7772920d..9f4cee052 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2020.06-dev (Red Hot Poker) --- DB_UPDATE_VERSION 1338 +-- DB_UPDATE_VERSION 1340 -- ------------------------------------------ @@ -1175,6 +1175,31 @@ CREATE TABLE IF NOT EXISTS `term` ( INDEX `guid` (`guid`(64)) ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='item taxonomy (categories, tags, etc.) table'; +-- +-- TABLE tag +-- +CREATE TABLE IF NOT EXISTS `tag` ( + `id` int unsigned NOT NULL auto_increment COMMENT '', + `name` varchar(96) NOT NULL DEFAULT '' COMMENT '', + `url` varbinary(255) NOT NULL DEFAULT '' COMMENT '', + PRIMARY KEY(`id`), + UNIQUE INDEX `type_name_url` (`name`,`url`), + INDEX `url` (`url`) +) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions'; + +-- +-- TABLE post-tag +-- +CREATE TABLE IF NOT EXISTS `post-tag` ( + `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri', + `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '', + `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '', + `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact', + PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`), + INDEX `uri-id` (`tid`), + INDEX `cid` (`tid`) +) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags'; + -- -- TABLE thread -- @@ -1361,4 +1386,22 @@ CREATE TABLE IF NOT EXISTS `storage` ( PRIMARY KEY(`id`) ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend'; +-- +-- VIEW tag-view +-- +DROP VIEW IF EXISTS `tag-view`; +CREATE VIEW `tag-view` AS SELECT + `post-tag`.`uri-id` AS `uri-id`, + `item-uri`.`uri` AS `uri`, + `item-uri`.`guid` AS `guid`, + `post-tag`.`type` AS `type`, + `post-tag`.`tid` AS `tid`, + `post-tag`.`cid` AS `cid`, + CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`, + CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url` + FROM `post-tag` + INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id` + LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id` + LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`; + diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 6fe4d614d..372e3c496 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -112,6 +112,8 @@ class DBStructure echo "\n"; } + + DBView::printStructure($basePath); } /** @@ -594,6 +596,8 @@ class DBStructure } } + DBView::create($verbose, $action); + if ($action && !$install) { DI::config()->set('system', 'maintenance', 0); DI::config()->set('system', 'maintenance_reason', ''); diff --git a/src/Database/DBView.php b/src/Database/DBView.php new file mode 100644 index 000000000..f23ab152e --- /dev/null +++ b/src/Database/DBView.php @@ -0,0 +1,138 @@ +. + * + */ + +namespace Friendica\Database; + +use Exception; +use Friendica\Core\Hook; +use Friendica\Core\Logger; +use Friendica\DI; +use Friendica\Util\DateTimeFormat; +use phpDocumentor\Reflection\Types\Boolean; + +require_once __DIR__ . '/../../include/dba.php'; + +class DBView +{ + /** + * view definition loaded from config/dbview.config.php + * + * @var array + */ + private static $definition = []; + + /** + * Loads the database structure definition from the config/dbview.config.php file. + * On first pass, defines DB_UPDATE_VERSION constant. + * + * @see static/dbview.config.php + * @param boolean $with_addons_structure Whether to tack on addons additional tables + * @param string $basePath The base path of this application + * @return array + * @throws Exception + */ + public static function definition($basePath = '', $with_addons_structure = true) + { + if (!self::$definition) { + if (empty($basePath)) { + $basePath = DI::app()->getBasePath(); + } + + $filename = $basePath . '/static/dbview.config.php'; + + if (!is_readable($filename)) { + throw new Exception('Missing database view config file static/dbview.config.php'); + } + + $definition = require $filename; + + if (!$definition) { + throw new Exception('Corrupted database view config file static/dbview.config.php'); + } + + self::$definition = $definition; + } else { + $definition = self::$definition; + } + + if ($with_addons_structure) { + Hook::callAll('dbview_definition', $definition); + } + + return $definition; + } + + public static function create(bool $verbose, bool $action) + { + $definition = self::definition(); + + foreach ($definition as $name => $structure) { + self::createview($name, $structure, $verbose, $action); + } + } + + public static function printStructure($basePath) + { + $database = self::definition($basePath, false); + + foreach ($database AS $name => $structure) { + echo "--\n"; + echo "-- VIEW $name\n"; + echo "--\n"; + self::createView($name, $structure, true, false); + + echo "\n"; + } + } + + private static function createview($name, $structure, $verbose, $action) + { + $r = true; + + $sql_rows = []; + foreach ($structure["fields"] AS $fieldname => $origin) { + $sql_rows[] = $origin . " AS `" . DBA::escape($fieldname) . "`"; + } + + $sql = sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($name)); + + if ($verbose) { + echo $sql . ";\n"; + } + + if ($action) { + DBA::e($sql); + } + + $sql = sprintf("CREATE VIEW `%s` AS SELECT \n\t", DBA::escape($name)) . + implode(",\n\t", $sql_rows) . "\n\t" . $structure['query']; + + if ($verbose) { + echo $sql . ";\n"; + } + + if ($action) { + $r = DBA::e($sql); + } + + return $r; + } +} diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 4eabe2d37..50055f62a 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -51,7 +51,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1339); + define('DB_UPDATE_VERSION', 1340); } return [ diff --git a/static/dbview.config.php b/static/dbview.config.php new file mode 100755 index 000000000..6bc327697 --- /dev/null +++ b/static/dbview.config.php @@ -0,0 +1,56 @@ +. + * + * Main view structure configuration file. + * + * Here are described all the view Friendica needs to work. + * + * Syntax (braces indicate optionale values): + * "" => [ + * "fields" => [ + * "" => "`table`.`field`", + * "" => "`other-table`.`field`", + * "" => "SQL expression", + * ... + * ], + * "query" => "FROM `table` INNER JOIN `other-table` ..." + * ], + * ], + * + * If you need to make any change, make sure to increment the DB_UPDATE_VERSION constant value in dbstructure.config.php. + * + */ + +return [ + "tag-view" => [ + "fields" => ["uri-id" => "`post-tag`.`uri-id`", + "uri" => "`item-uri`.`uri`", + "guid" => "`item-uri`.`guid`", + "type" => "`post-tag`.`type`", + "tid" => "`post-tag`.`tid`", + "cid" => "`post-tag`.`cid`", + "name" => "CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END", + "url" => "CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END"], + "query" => "FROM `post-tag` + INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id` + LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id` + LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`" + ] +]; + From c3aa2730deb92d1f7fbe768381cd8b36512d235d Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 23 Apr 2020 07:02:18 +0000 Subject: [PATCH 02/30] Improved definition style --- src/Database/DBView.php | 6 +++++- static/dbview.config.php | 15 +++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Database/DBView.php b/src/Database/DBView.php index f23ab152e..cd1d22e1e 100644 --- a/src/Database/DBView.php +++ b/src/Database/DBView.php @@ -109,7 +109,11 @@ class DBView $sql_rows = []; foreach ($structure["fields"] AS $fieldname => $origin) { - $sql_rows[] = $origin . " AS `" . DBA::escape($fieldname) . "`"; + if (is_string($origin)) { + $sql_rows[] = $origin . " AS `" . DBA::escape($fieldname) . "`"; + } elseif (is_array($origin) && (sizeof($origin) == 2)) { + $sql_rows[] = "`" . DBA::escape($origin[0]) . "`.`" . DBA::escape($origin[1]) . "` AS `" . DBA::escape($fieldname) . "`"; + } } $sql = sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($name)); diff --git a/static/dbview.config.php b/static/dbview.config.php index 6bc327697..165ae2fa1 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -24,8 +24,7 @@ * Syntax (braces indicate optionale values): * "" => [ * "fields" => [ - * "" => "`table`.`field`", - * "" => "`other-table`.`field`", + * "" => ["table", "field"], * "" => "SQL expression", * ... * ], @@ -39,12 +38,12 @@ return [ "tag-view" => [ - "fields" => ["uri-id" => "`post-tag`.`uri-id`", - "uri" => "`item-uri`.`uri`", - "guid" => "`item-uri`.`guid`", - "type" => "`post-tag`.`type`", - "tid" => "`post-tag`.`tid`", - "cid" => "`post-tag`.`cid`", + "fields" => ["uri-id" => ["post-tag", "uri-id"], + "uri" => ["item-uri", "uri"], + "guid" => ["item-uri", "guid"], + "type" => ["post-tag", "type"], + "tid" => ["post-tag", "tid"], + "cid" => ["post-tag", "cid"], "name" => "CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END", "url" => "CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END"], "query" => "FROM `post-tag` From bc1efdaf539cd7c2f5783c04b70e4235fd941b5c Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 05:37:06 +0000 Subject: [PATCH 03/30] Code standards --- static/dbview.config.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/static/dbview.config.php b/static/dbview.config.php index 165ae2fa1..6b6a8e53f 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -38,14 +38,16 @@ return [ "tag-view" => [ - "fields" => ["uri-id" => ["post-tag", "uri-id"], + "fields" => [ + "uri-id" => ["post-tag", "uri-id"], "uri" => ["item-uri", "uri"], "guid" => ["item-uri", "guid"], "type" => ["post-tag", "type"], "tid" => ["post-tag", "tid"], "cid" => ["post-tag", "cid"], "name" => "CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END", - "url" => "CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END"], + "url" => "CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END", + ], "query" => "FROM `post-tag` INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id` LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id` From b50aaf87d71ffc61792f4993fe7ebf637c7b7aa5 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 05:39:30 +0000 Subject: [PATCH 04/30] Some more code standards --- static/dbview.config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/dbview.config.php b/static/dbview.config.php index 6b6a8e53f..ad33a7882 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -52,6 +52,6 @@ return [ INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id` LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id` LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`" - ] + ], ]; From afa712b8112e8e827112b3438f65e781da95b91a Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 08:48:34 +0000 Subject: [PATCH 05/30] DBView is View --- src/Database/DBStructure.php | 4 ++-- src/Database/{DBView.php => View.php} | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) rename src/Database/{DBView.php => View.php} (96%) diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 372e3c496..1433a5346 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -113,7 +113,7 @@ class DBStructure echo "\n"; } - DBView::printStructure($basePath); + View::printStructure($basePath); } /** @@ -596,7 +596,7 @@ class DBStructure } } - DBView::create($verbose, $action); + View::create($verbose, $action); if ($action && !$install) { DI::config()->set('system', 'maintenance', 0); diff --git a/src/Database/DBView.php b/src/Database/View.php similarity index 96% rename from src/Database/DBView.php rename to src/Database/View.php index cd1d22e1e..fa4c502a2 100644 --- a/src/Database/DBView.php +++ b/src/Database/View.php @@ -23,14 +23,11 @@ namespace Friendica\Database; use Exception; use Friendica\Core\Hook; -use Friendica\Core\Logger; use Friendica\DI; -use Friendica\Util\DateTimeFormat; -use phpDocumentor\Reflection\Types\Boolean; require_once __DIR__ . '/../../include/dba.php'; -class DBView +class View { /** * view definition loaded from config/dbview.config.php From 02aed490e2f7d0862d002a0a984cd5a0442ee75c Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 11:04:50 +0000 Subject: [PATCH 06/30] Owner-view added --- src/Model/Tag.php | 13 +++-- src/Model/User.php | 85 +++++++++----------------------- src/Module/Admin/Users.php | 14 +++--- static/dbview.config.php | 99 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 73 deletions(-) diff --git a/src/Model/Tag.php b/src/Model/Tag.php index e2ce5ad0d..cf453f243 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -231,13 +231,18 @@ class Tag */ public static function remove(int $uriid, int $type, string $name, string $url = '') { - $tag = DBA::fetchFirst("SELECT `id` FROM `tag` INNER JOIN `post-tag` ON `post-tag`.`tid` = `tag`.`id` - WHERE `uri-id` = ? AND `type` = ? AND `name` = ? AND `url` = ?", $uriid, $type, $name, $url); + $condition = ['uri-id' => $uriid, 'type' => $type, 'url' => $url]; + if ($type == self::HASHTAG) { + $condition['name'] = $name; + } + + $tag = DBA::selectFirst('tag-view', ['tid', 'cid'], $condition); if (!DBA::isResult($tag)) { return; } - Logger::info('Removing tag/mention', ['uri-id' => $uriid, 'tid' => $tag['id'], 'name' => $name, 'url' => $url, 'callstack' => System::callstack(8)]); - DBA::delete('post-tag', ['uri-id' => $uriid, 'tid' => $tag['id']]); + + Logger::info('Removing tag/mention', ['uri-id' => $uriid, 'tid' => $tag['tid'], 'name' => $name, 'url' => $url, 'callstack' => System::callstack(8)]); + DBA::delete('post-tag', ['uri-id' => $uriid, 'type' => $type, 'tid' => $tag['tid'], 'cid' => $tag['cid']]); } /** diff --git a/src/Model/User.php b/src/Model/User.php index 4ef5ffa33..e7f2f89ad 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -195,66 +195,46 @@ class User */ public static function getOwnerDataById($uid, $check_valid = true) { - $r = DBA::fetchFirst( - "SELECT - `contact`.*, - `user`.`prvkey` AS `uprvkey`, - `user`.`timezone`, - `user`.`nickname`, - `user`.`sprvkey`, - `user`.`spubkey`, - `user`.`page-flags`, - `user`.`account-type`, - `user`.`prvnets`, - `user`.`account_removed`, - `user`.`hidewall` - FROM `contact` - INNER JOIN `user` - ON `user`.`uid` = `contact`.`uid` - WHERE `contact`.`uid` = ? - AND `contact`.`self` - LIMIT 1", - $uid - ); - if (!DBA::isResult($r)) { + $owner = DBA::selectFirst('owner-view', [], ['uid' => $uid]); + if (!DBA::isResult($owner)) { return false; } - if (empty($r['nickname'])) { + if (empty($owner['nickname'])) { return false; } if (!$check_valid) { - return $r; + return $owner; } // Check if the returned data is valid, otherwise fix it. See issue #6122 // Check for correct url and normalised nurl - $url = DI::baseUrl() . '/profile/' . $r['nickname']; - $repair = ($r['url'] != $url) || ($r['nurl'] != Strings::normaliseLink($r['url'])); + $url = DI::baseUrl() . '/profile/' . $owner['nickname']; + $repair = ($owner['url'] != $url) || ($owner['nurl'] != Strings::normaliseLink($owner['url'])); if (!$repair) { // Check if "addr" is present and correct - $addr = $r['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3); - $repair = ($addr != $r['addr']); + $addr = $owner['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3); + $repair = ($addr != $owner['addr']); } if (!$repair) { // Check if the avatar field is filled and the photo directs to the correct path $avatar = Photo::selectFirst(['resource-id'], ['uid' => $uid, 'profile' => true]); if (DBA::isResult($avatar)) { - $repair = empty($r['avatar']) || !strpos($r['photo'], $avatar['resource-id']); + $repair = empty($owner['avatar']) || !strpos($owner['photo'], $avatar['resource-id']); } } if ($repair) { Contact::updateSelfFromUserID($uid); // Return the corrected data and avoid a loop - $r = self::getOwnerDataById($uid, false); + $owner = self::getOwnerDataById($uid, false); } - return $r; + return $owner; } /** @@ -1290,17 +1270,10 @@ class User 'active_users_monthly' => 0, ]; - $userStmt = DBA::p("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item` - FROM `user` - INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` - WHERE `user`.`verified` - AND `user`.`login_date` > ? - AND NOT `user`.`blocked` - AND NOT `user`.`account_removed` - AND NOT `user`.`account_expired`", - DBA::NULL_DATETIME - ); - + $userStmt = DBA::select('owner-view', ['uid', 'login_date', 'last-item'], + ["`verified` AND `login_date` > ? AND NOT `blocked` + AND NOT `account_removed` AND NOT `account_expired`", + DBA::NULL_DATETIME]); if (!DBA::isResult($userStmt)) { return $statistics; } @@ -1332,39 +1305,27 @@ class User * @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE) * @param string $type The type of users, which should get (all, bocked, removed) * @param string $order Order of the user list (Default is 'contact.name') - * @param string $order_direction Order direction (Default is ASC) + * @param bool $descending Order direction (Default is ascending) * * @return array The list of the users * @throws Exception */ - public static function getList($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'contact.name', $order_direction = '+') + public static function getList($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'name', bool $descending = false) { - $sql_order = '`' . str_replace('.', '`.`', $order) . '`'; - $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC'; - + $param = ['limit' => [$start, $count], 'order' => [$order => $descending]]; + $condition = []; switch ($type) { case 'active': - $sql_extra = 'AND `user`.`blocked` = 0'; + $condition['blocked'] = false; break; case 'blocked': - $sql_extra = 'AND `user`.`blocked` = 1'; + $condition['blocked'] = true; break; case 'removed': - $sql_extra = 'AND `user`.`account_removed` = 1'; - break; - case 'all': - default: - $sql_extra = ''; + $condition['account_removed'] = true; break; } - $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`, `contact`.`nick`, `contact`.`created` - FROM `user` - INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` - WHERE `user`.`verified` $sql_extra - ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $start, $count - ); - - return DBA::toArray($usersStmt); + return DBA::selectToArray('owner-view', [], $condition, $param); } } diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 3ef91aadf..822ac0c01 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -157,15 +157,15 @@ class Users extends BaseAdmin $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 100); $valid_orders = [ - 'contact.name', - 'user.email', - 'user.register_date', - 'user.login_date', + 'name', + 'email', + 'register_date', + 'login_date', 'lastitem_date', - 'user.page-flags' + 'page-flags' ]; - $order = 'contact.name'; + $order = 'name'; $order_direction = '+'; if (!empty($_GET['o'])) { $new_order = $_GET['o']; @@ -179,7 +179,7 @@ class Users extends BaseAdmin } } - $users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, $order_direction); + $users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, ($order_direction == '-')); $adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email'))); $_setup_users = function ($e) use ($adminlist) { diff --git a/static/dbview.config.php b/static/dbview.config.php index ad33a7882..0d44df031 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -53,5 +53,104 @@ return [ LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id` LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`" ], + "owner-view" => [ + "fields" => [ + "id" => ["contact", "id"], + "uid" => ["contact", "uid"], + "created" => ["contact", "created"], + "updated" => ["contact", "updated"], + "self" => ["contact", "self"], + "remote_self" => ["contact", "remote_self"], + "rel" => ["contact", "rel"], + "duplex" => ["contact", "duplex"], + "network" => ["contact", "network"], + "protocol" => ["contact", "protocol"], + "name" => ["contact", "name"], + "nick" => ["contact", "nick"], + "location" => ["contact", "location"], + "about" => ["contact", "about"], + "keywords" => ["contact", "keywords"], + "gender" => ["contact", "gender"], + "xmpp" => ["contact", "xmpp"], + "attag" => ["contact", "attag"], + "avatar" => ["contact", "avatar"], + "photo" => ["contact", "photo"], + "thumb" => ["contact", "thumb"], + "micro" => ["contact", "micro"], + "site-pubkey" => ["contact", "site-pubkey"], + "issued-id" => ["contact", "issued-id"], + "dfrn-id" => ["contact", "dfrn-id"], + "url" => ["contact", "url"], + "nurl" => ["contact", "nurl"], + "addr" => ["contact", "addr"], + "alias" => ["contact", "alias"], + "pubkey" => ["contact", "pubkey"], + "prvkey" => ["contact", "prvkey"], + "batch" => ["contact", "batch"], + "request" => ["contact", "request"], + "notify" => ["contact", "notify"], + "poll" => ["contact", "poll"], + "confirm" => ["contact", "confirm"], + "poco" => ["contact", "poco"], + "aes_allow" => ["contact", "aes_allow"], + "ret-aes" => ["contact", "ret-aes"], + "usehub" => ["contact", "usehub"], + "subhub" => ["contact", "subhub"], + "hub-verify" => ["contact", "hub-verify"], + "last-update" => ["contact", "last-update"], + "success_update" => ["contact", "success_update"], + "failure_update" => ["contact", "failure_update"], + "name-date" => ["contact", "name-date"], + "uri-date" => ["contact", "uri-date"], + "avatar-date" => ["contact", "avatar-date"], + "term-date" => ["contact", "term-date"], + "last-item" => ["contact", "last-item"], + "lastitem_date" => ["contact", "last-item"], + "priority" => ["contact", "priority"], + "blocked" => ["contact", "blocked"], + "block_reason" => ["contact", "block_reason"], + "readonly" => ["contact", "readonly"], + "writable" => ["contact", "writable"], + "forum" => ["contact", "forum"], + "prv" => ["contact", "prv"], + "contact-type" => ["contact", "contact-type"], + "hidden" => ["contact", "hidden"], + "archive" => ["contact", "archive"], + "pending" => ["contact", "pending"], + "deleted" => ["contact", "deleted"], + "rating" => ["contact", "rating"], + "unsearchable" => ["contact", "unsearchable"], + "sensitive" => ["contact", "sensitive"], + "baseurl" => ["contact", "baseurl"], + "reason" => ["contact", "reason"], + "closeness" => ["contact", "closeness"], + "info" => ["contact", "info"], + "profile-id" => ["contact", "profile-id"], + "bdyear" => ["contact", "bdyear"], + "bd" => ["contact", "bd"], + "notify_new_posts" => ["notify_new_posts"], + "fetch_further_information" => ["fetch_further_information"], + "ffi_keyword_blacklist" => ["ffi_keyword_blacklist"], + "email" => ["user", "email"], + "uprvkey" => ["user", "prvkey"], + "timezone" => ["user", "timezone"], + "nickname" => ["user", "nickname"], + "sprvkey" => ["user", "sprvkey"], + "spubkey" => ["user", "spubkey"], + "page-flags" => ["user", "page-flags"], + "account-type" => ["user", "account-type"], + "prvnets" => ["user", "prvnets"], + "account_removed" => ["user", "account_removed"], + "hidewall" => ["user", "hidewall"], + "login_date" => ["user", "login_date"], + "register_date" => ["user", "register_date"], + "verified" => ["user", "verified"], + "account_removed" => ["user", "account_removed"], + "account_expired" => ["user", "account_expired"], + "account_expires_on" => ["user", "account_expires_on"], + ], + "query" => "FROM `user` + INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`" + ] ]; From 4181eb37f58b21bd03700b1711879df89a57a0b2 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 11:55:46 +0000 Subject: [PATCH 07/30] More joins replaced by view calls --- mod/poco.php | 5 +---- src/Worker/Directory.php | 14 ++++---------- static/dbview.config.php | 25 +++++++++++++++++++++---- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/mod/poco.php b/mod/poco.php index f04ec4279..edbe73dce 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -81,10 +81,7 @@ function poco_init(App $a) { } if (!$system_mode && !$global) { - $user = DBA::fetchFirst("SELECT `user`.`uid`, `user`.`nickname` FROM `user` - INNER JOIN `profile` ON `user`.`uid` = `profile`.`uid` - WHERE `user`.`nickname` = ? AND NOT `profile`.`hide-friends`", - $nickname); + $user = DBA::selectFirst('owner-view', ['uid', 'nickname'], ['nickname' => $nickname, 'hide-friends' => false]); if (!DBA::isResult($user)) { throw new \Friendica\Network\HTTPException\NotFoundException(); } diff --git a/src/Worker/Directory.php b/src/Worker/Directory.php index ff844ca39..6c6d26f26 100644 --- a/src/Worker/Directory.php +++ b/src/Worker/Directory.php @@ -61,16 +61,10 @@ class Directory } private static function updateAll() { - $r = q("SELECT `url` FROM `contact` - INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid` - INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` - WHERE `contact`.`self` AND `profile`.`net-publish` AND - NOT `user`.`account_expired` AND `user`.`verified`"); - - if (DBA::isResult($r)) { - foreach ($r AS $user) { - Worker::add(PRIORITY_LOW, 'Directory', $user['url']); - } + $users = DBA::select('owner-view', ['url'], ['net-publish' => true, 'account_expired' => false, 'verified' => true]); + while ($user = DBA::fetch($users)) { + Worker::add(PRIORITY_LOW, 'Directory', $user['url']); } + DBA::close($users); } } diff --git a/static/dbview.config.php b/static/dbview.config.php index 0d44df031..0fd4048ca 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -105,9 +105,9 @@ return [ "avatar-date" => ["contact", "avatar-date"], "term-date" => ["contact", "term-date"], "last-item" => ["contact", "last-item"], - "lastitem_date" => ["contact", "last-item"], + "lastitem_date" => ["contact", "last-item"], /// @todo Replaces all uses of "lastitem_date" with "last-item" "priority" => ["contact", "priority"], - "blocked" => ["contact", "blocked"], + "blocked" => ["contact", "blocked"], /// @todo Check if "blocked" from contact or from the users table "block_reason" => ["contact", "block_reason"], "readonly" => ["contact", "readonly"], "writable" => ["contact", "writable"], @@ -133,8 +133,9 @@ return [ "ffi_keyword_blacklist" => ["ffi_keyword_blacklist"], "email" => ["user", "email"], "uprvkey" => ["user", "prvkey"], + "upubkey" => ["user", "pubkey"], "timezone" => ["user", "timezone"], - "nickname" => ["user", "nickname"], + "nickname" => ["user", "nickname"], /// @todo Remove duplicate "sprvkey" => ["user", "sprvkey"], "spubkey" => ["user", "spubkey"], "page-flags" => ["user", "page-flags"], @@ -145,12 +146,28 @@ return [ "login_date" => ["user", "login_date"], "register_date" => ["user", "register_date"], "verified" => ["user", "verified"], + "expire" => ["user", "expire"], + "expire_notification_sent" => ["user", "expire_notification_sent"], "account_removed" => ["user", "account_removed"], "account_expired" => ["user", "account_expired"], "account_expires_on" => ["user", "account_expires_on"], + "publish" => ["profile", "publish"], + "net-publish" => ["profile", "net-publish"], + "hide-friends" => ["profile", "hide-friends"], + "prv_keywords" => ["profile", "prv_keywords"], + "pub_keywords" => ["profile", "pub_keywords"], + "address" => ["profile", "address"], + "locality" => ["profile", "locality"], + "region" => ["profile", "region"], + "postal-code" => ["profile", "postal-code"], + "country-name" => ["profile", "country-name"], + "homepage" => ["profile", "homepage"], + "xmpp" => ["profile", "xmpp"], + "dob" => ["profile", "dob"], ], "query" => "FROM `user` - INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`" + INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` + INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`" ] ]; From 0950e4badaa54d7d6f689b39753e54c053d8c885 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 12:09:51 +0000 Subject: [PATCH 08/30] Another view --- mod/wall_upload.php | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/mod/wall_upload.php b/mod/wall_upload.php index ad0b5d3c0..093d5db77 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -45,15 +45,9 @@ function wall_upload_post(App $a, $desktopmode = true) if ($a->argc > 1) { if (empty($_FILES['media'])) { - $nick = $a->argv[1]; - $r = q("SELECT `user`.*, `contact`.`id` FROM `user` - INNER JOIN `contact` on `user`.`uid` = `contact`.`uid` - WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 - AND `contact`.`self` = 1 LIMIT 1", - DBA::escape($nick) - ); - - if (!DBA::isResult($r)) { + $nick = $a->argv[1]; + $user = DBA::selectFirst('owner-view', ['id', 'uid', 'nickname', 'page-flags'], ['nickname' => $nick, 'blocked' => false]); + if (!DBA::isResult($user)) { if ($r_json) { echo json_encode(['error' => DI::l10n()->t('Invalid request.')]); exit(); @@ -62,12 +56,7 @@ function wall_upload_post(App $a, $desktopmode = true) } } else { $user_info = api_get_user($a); - $r = q("SELECT `user`.*, `contact`.`id` FROM `user` - INNER JOIN `contact` on `user`.`uid` = `contact`.`uid` - WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 - AND `contact`.`self` = 1 LIMIT 1", - DBA::escape($user_info['screen_name']) - ); + $user = DBA::selectFirst('owner-view', ['id', 'uid', 'nickname', 'page-flags'], ['nickname' => $user_info['screen_name'], 'blocked' => false]); } } else { if ($r_json) { @@ -83,10 +72,10 @@ function wall_upload_post(App $a, $desktopmode = true) $can_post = false; $visitor = 0; - $page_owner_uid = $r[0]['uid']; - $default_cid = $r[0]['id']; - $page_owner_nick = $r[0]['nickname']; - $community_page = (($r[0]['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false); + $page_owner_uid = $user['uid']; + $default_cid = $user['id']; + $page_owner_nick = $user['nickname']; + $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false); if ((local_user()) && (local_user() == $page_owner_uid)) { $can_post = true; From 3e5c3dce01ee56ec51d7bfa4e687c4e2f86d9388 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 12:24:10 +0000 Subject: [PATCH 09/30] Next join replaced by view --- src/Protocol/Diaspora.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 513cd0bcc..19ef391a0 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -4170,20 +4170,11 @@ class Diaspora */ private static function createProfileData($uid) { - $r = q( - "SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.*, `user`.`prvkey` AS `uprvkey`, `contact`.`addr` - FROM `profile` - INNER JOIN `user` ON `profile`.`uid` = `user`.`uid` - INNER JOIN `contact` ON `profile`.`uid` = `contact`.`uid` - WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1", - intval($uid) - ); - - if (!$r) { + $profile = DBA::selectFirst('owner-view', ['uid', 'addr', 'name', 'location', 'net-publish', 'dob', 'about', 'pub_keywords'], ['uid' => $uid]); + if (!DBA::isResult($profile)) { return []; } - $profile = $r[0]; $handle = $profile["addr"]; $split_name = self::splitName($profile['name']); @@ -4212,7 +4203,7 @@ class Diaspora $about = BBCode::toMarkdown($profile['about']); - $location = Profile::formatLocation($profile); + $location = $profile['location']; $tags = ''; if ($profile['pub_keywords']) { $kw = str_replace(',', ' ', $profile['pub_keywords']); From c4f7f3e26ecd867d1d99238b056b8d11bb52a2a1 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 12:59:19 +0000 Subject: [PATCH 10/30] And some more view calls added --- mod/display.php | 6 +----- src/Model/Profile.php | 20 ++++---------------- static/dbview.config.php | 2 ++ 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/mod/display.php b/mod/display.php index 107e666d4..a06d8a723 100644 --- a/mod/display.php +++ b/mod/display.php @@ -116,11 +116,7 @@ function display_init(App $a) $nickname = str_replace(Strings::normaliseLink(DI::baseUrl()) . '/profile/', '', Strings::normaliseLink($profiledata['url'])); if (!empty($a->user['nickname']) && $nickname != $a->user['nickname']) { - $profile = DBA::fetchFirst("SELECT `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile` - INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid` - WHERE `user`.`nickname` = ? AND `contact`.`self` LIMIT 1", - $nickname - ); + $profile = DBA::selectFirst('owner-view', [], ['nickname' => $nickname]); if (DBA::isResult($profile)) { $profiledata = $profile; } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 867a6db4f..ec862947b 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -234,19 +234,7 @@ class Profile */ public static function getByNickname($nickname, $uid = 0) { - $profile = DBA::fetchFirst( - "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`, - `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`, - `profile`.*, - `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.* - FROM `profile` - INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self` - INNER JOIN `user` ON `profile`.`uid` = `user`.`uid` - WHERE `user`.`nickname` = ? AND `profile`.`uid` = ? LIMIT 1", - $nickname, - intval($uid) - ); - + $profile = DBA::selectFirst('owner-view', [], ['nickname' => $nickname, 'uid' => $uid]); return $profile; } @@ -399,9 +387,9 @@ class Profile 'fullname' => $profile['name'], 'firstname' => $firstname, 'lastname' => $lastname, - 'photo300' => $profile['contact_photo'] ?? '', - 'photo100' => $profile['contact_thumb'] ?? '', - 'photo50' => $profile['contact_micro'] ?? '', + 'photo300' => $profile['photo'] ?? '', + 'photo100' => $profile['thumb'] ?? '', + 'photo50' => $profile['micro'] ?? '', ]; } else { $diaspora = false; diff --git a/static/dbview.config.php b/static/dbview.config.php index 0fd4048ca..06f7d3aa9 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -103,6 +103,8 @@ return [ "name-date" => ["contact", "name-date"], "uri-date" => ["contact", "uri-date"], "avatar-date" => ["contact", "avatar-date"], + "contact_id" => ["contact", "id"], /// @todo Replaces all uses of "contact_id" with "id" + "picdate" => ["contact", "avatar-date"], /// @todo Replaces all uses of "picdate" with "avatar-date" "term-date" => ["contact", "term-date"], "last-item" => ["contact", "last-item"], "lastitem_date" => ["contact", "last-item"], /// @todo Replaces all uses of "lastitem_date" with "last-item" From a5aa43469b2299baae05d63327ecf23b31f115e8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 13:41:11 +0000 Subject: [PATCH 11/30] Some more places with owner-view --- mod/poco.php | 53 +++++++++------------------------------- src/Protocol/DFRN.php | 27 +++++--------------- static/dbview.config.php | 6 ++++- 3 files changed, 22 insertions(+), 64 deletions(-) diff --git a/mod/poco.php b/mod/poco.php index edbe73dce..ef77c9c99 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -144,16 +144,7 @@ function poco_init(App $a) { ); } elseif ($system_mode) { Logger::log("Start system mode query", Logger::DEBUG); - $contacts = q("SELECT `contact`.*, `profile`.`about` AS `pabout`, `profile`.`locality` AS `plocation`, `profile`.`pub_keywords`, - `profile`.`address` AS `paddress`, `profile`.`region` AS `pregion`, - `profile`.`postal-code` AS `ppostalcode`, `profile`.`country-name` AS `pcountry`, `user`.`account-type` - FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid` - INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` - WHERE `self` = 1 AND `profile`.`net-publish` - LIMIT %d, %d", - intval($startIndex), - intval($itemsPerPage) - ); + $contacts = DBA::selectToArray('owner-view', [], ['net-publish' => true], ['limit' => [$startIndex, $itemsPerPage]]); } else { Logger::log("Start query for user " . $user['nickname'], Logger::DEBUG); $contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 @@ -230,28 +221,6 @@ function poco_init(App $a) { } } - if (($contact['about'] == "") && isset($contact['pabout'])) { - $contact['about'] = $contact['pabout']; - } - if ($contact['location'] == "") { - if (isset($contact['plocation'])) { - $contact['location'] = $contact['plocation']; - } - if (isset($contact['pregion']) && ( $contact['pregion'] != "")) { - if ($contact['location'] != "") { - $contact['location'] .= ", "; - } - $contact['location'] .= $contact['pregion']; - } - - if (isset($contact['pcountry']) && ( $contact['pcountry'] != "")) { - if ($contact['location'] != "") { - $contact['location'] .= ", "; - } - $contact['location'] .= $contact['pcountry']; - } - } - if (($contact['keywords'] == "") && isset($contact['pub_keywords'])) { $contact['keywords'] = $contact['pub_keywords']; } @@ -343,21 +312,21 @@ function poco_init(App $a) { $entry['address'] = []; // Deactivated. It just reveals too much data. (Although its from the default profile) - //if (isset($rr['paddress'])) - // $entry['address']['streetAddress'] = $rr['paddress']; + //if (isset($rr['address'])) + // $entry['address']['streetAddress'] = $rr['address']; - if (isset($contact['plocation'])) { - $entry['address']['locality'] = $contact['plocation']; + if (isset($contact['locality'])) { + $entry['address']['locality'] = $contact['locality']; } - if (isset($contact['pregion'])) { - $entry['address']['region'] = $contact['pregion']; + if (isset($contact['region'])) { + $entry['address']['region'] = $contact['region']; } // See above - //if (isset($rr['ppostalcode'])) - // $entry['address']['postalCode'] = $rr['ppostalcode']; + //if (isset($rr['postal-code'])) + // $entry['address']['postalCode'] = $rr['postal-code']; - if (isset($contact['pcountry'])) { - $entry['address']['country'] = $contact['pcountry']; + if (isset($contact['country'])) { + $entry['address']['country'] = $contact['country']; } } diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 83010f811..f65a202f4 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -183,19 +183,12 @@ class DFRN $sql_extra = sprintf(" AND `item`.`private` != %s ", Item::PRIVATE); - $r = q( - "SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type` - FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` - WHERE `contact`.`self` AND `user`.`nickname` = '%s' LIMIT 1", - DBA::escape($owner_nick) - ); - - if (! DBA::isResult($r)) { + $owner = DBA::selectFirst('owner-view', [], ['nickname' => $owner_nick]); + if (!DBA::isResult($owner)) { Logger::log(sprintf('No contact found for nickname=%d', $owner_nick), Logger::WARNING); exit(); } - $owner = $r[0]; $owner_id = $owner['uid']; $sql_post_table = ""; @@ -684,18 +677,10 @@ class DFRN } // Only show contact details when we are allowed to - $r = q( - "SELECT `profile`.`about`, `profile`.`name`, `profile`.`homepage`, `user`.`nickname`, - `user`.`timezone`, `profile`.`locality`, `profile`.`region`, `profile`.`country-name`, - `profile`.`pub_keywords`, `profile`.`xmpp`, `profile`.`dob` - FROM `profile` - INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` - WHERE NOT `user`.`hidewall` AND `user`.`uid` = %d", - intval($owner['uid']) - ); - if (DBA::isResult($r)) { - $profile = $r[0]; - + $profile = DBA::selectFirst('owner-view', + ['about', 'name', 'homepage', 'nickname', 'timezone', 'locality', 'region', 'country-name', 'pub_keywords', 'xmpp', 'dob'], + ['uid' => $owner['uid'], 'hidewall' => false]); + if (DBA::isResult($profile)) { XML::addElement($doc, $author, "poco:displayName", $profile["name"]); XML::addElement($doc, $author, "poco:updated", $namdate); diff --git a/static/dbview.config.php b/static/dbview.config.php index 06f7d3aa9..4363c7886 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -133,11 +133,15 @@ return [ "notify_new_posts" => ["notify_new_posts"], "fetch_further_information" => ["fetch_further_information"], "ffi_keyword_blacklist" => ["ffi_keyword_blacklist"], + "guid" => ["user", "guid"], + "theme" => ["user", "theme"], + "language" => ["user", "language"], "email" => ["user", "email"], "uprvkey" => ["user", "prvkey"], "upubkey" => ["user", "pubkey"], "timezone" => ["user", "timezone"], - "nickname" => ["user", "nickname"], /// @todo Remove duplicate + "nickname" => ["user", "nickname"], /// @todo Replaces all uses of "nickname" with "nick" + "username" => ["user", "username"], /// @todo Replaces all uses of "username" with "name" "sprvkey" => ["user", "sprvkey"], "spubkey" => ["user", "spubkey"], "page-flags" => ["user", "page-flags"], From 6011598bc204fab86d250ff625c65651232ee8f6 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 13:43:07 +0000 Subject: [PATCH 12/30] Database definition updated --- database.sql | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/database.sql b/database.sql index 9f4cee052..c7bd24f38 100644 --- a/database.sql +++ b/database.sql @@ -1404,4 +1404,123 @@ CREATE VIEW `tag-view` AS SELECT LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id` LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`; +-- +-- VIEW owner-view +-- +DROP VIEW IF EXISTS `owner-view`; +CREATE VIEW `owner-view` AS SELECT + `contact`.`id` AS `id`, + `contact`.`uid` AS `uid`, + `contact`.`created` AS `created`, + `contact`.`updated` AS `updated`, + `contact`.`self` AS `self`, + `contact`.`remote_self` AS `remote_self`, + `contact`.`rel` AS `rel`, + `contact`.`duplex` AS `duplex`, + `contact`.`network` AS `network`, + `contact`.`protocol` AS `protocol`, + `contact`.`name` AS `name`, + `contact`.`nick` AS `nick`, + `contact`.`location` AS `location`, + `contact`.`about` AS `about`, + `contact`.`keywords` AS `keywords`, + `contact`.`gender` AS `gender`, + `profile`.`xmpp` AS `xmpp`, + `contact`.`attag` AS `attag`, + `contact`.`avatar` AS `avatar`, + `contact`.`photo` AS `photo`, + `contact`.`thumb` AS `thumb`, + `contact`.`micro` AS `micro`, + `contact`.`site-pubkey` AS `site-pubkey`, + `contact`.`issued-id` AS `issued-id`, + `contact`.`dfrn-id` AS `dfrn-id`, + `contact`.`url` AS `url`, + `contact`.`nurl` AS `nurl`, + `contact`.`addr` AS `addr`, + `contact`.`alias` AS `alias`, + `contact`.`pubkey` AS `pubkey`, + `contact`.`prvkey` AS `prvkey`, + `contact`.`batch` AS `batch`, + `contact`.`request` AS `request`, + `contact`.`notify` AS `notify`, + `contact`.`poll` AS `poll`, + `contact`.`confirm` AS `confirm`, + `contact`.`poco` AS `poco`, + `contact`.`aes_allow` AS `aes_allow`, + `contact`.`ret-aes` AS `ret-aes`, + `contact`.`usehub` AS `usehub`, + `contact`.`subhub` AS `subhub`, + `contact`.`hub-verify` AS `hub-verify`, + `contact`.`last-update` AS `last-update`, + `contact`.`success_update` AS `success_update`, + `contact`.`failure_update` AS `failure_update`, + `contact`.`name-date` AS `name-date`, + `contact`.`uri-date` AS `uri-date`, + `contact`.`avatar-date` AS `avatar-date`, + `contact`.`id` AS `contact_id`, + `contact`.`avatar-date` AS `picdate`, + `contact`.`term-date` AS `term-date`, + `contact`.`last-item` AS `last-item`, + `contact`.`last-item` AS `lastitem_date`, + `contact`.`priority` AS `priority`, + `contact`.`blocked` AS `blocked`, + `contact`.`block_reason` AS `block_reason`, + `contact`.`readonly` AS `readonly`, + `contact`.`writable` AS `writable`, + `contact`.`forum` AS `forum`, + `contact`.`prv` AS `prv`, + `contact`.`contact-type` AS `contact-type`, + `contact`.`hidden` AS `hidden`, + `contact`.`archive` AS `archive`, + `contact`.`pending` AS `pending`, + `contact`.`deleted` AS `deleted`, + `contact`.`rating` AS `rating`, + `contact`.`unsearchable` AS `unsearchable`, + `contact`.`sensitive` AS `sensitive`, + `contact`.`baseurl` AS `baseurl`, + `contact`.`reason` AS `reason`, + `contact`.`closeness` AS `closeness`, + `contact`.`info` AS `info`, + `contact`.`profile-id` AS `profile-id`, + `contact`.`bdyear` AS `bdyear`, + `contact`.`bd` AS `bd`, + `user`.`guid` AS `guid`, + `user`.`theme` AS `theme`, + `user`.`language` AS `language`, + `user`.`email` AS `email`, + `user`.`prvkey` AS `uprvkey`, + `user`.`pubkey` AS `upubkey`, + `user`.`timezone` AS `timezone`, + `user`.`nickname` AS `nickname`, + `user`.`username` AS `username`, + `user`.`sprvkey` AS `sprvkey`, + `user`.`spubkey` AS `spubkey`, + `user`.`page-flags` AS `page-flags`, + `user`.`account-type` AS `account-type`, + `user`.`prvnets` AS `prvnets`, + `user`.`account_removed` AS `account_removed`, + `user`.`hidewall` AS `hidewall`, + `user`.`login_date` AS `login_date`, + `user`.`register_date` AS `register_date`, + `user`.`verified` AS `verified`, + `user`.`expire` AS `expire`, + `user`.`expire_notification_sent` AS `expire_notification_sent`, + `user`.`account_expired` AS `account_expired`, + `user`.`account_expires_on` AS `account_expires_on`, + `profile`.`publish` AS `publish`, + `profile`.`net-publish` AS `net-publish`, + `profile`.`hide-friends` AS `hide-friends`, + `profile`.`prv_keywords` AS `prv_keywords`, + `profile`.`pub_keywords` AS `pub_keywords`, + `profile`.`address` AS `address`, + `profile`.`locality` AS `locality`, + `profile`.`region` AS `region`, + `profile`.`postal-code` AS `postal-code`, + `profile`.`country-name` AS `country-name`, + `profile`.`homepage` AS `homepage`, + `profile`.`dob` AS `dob` + FROM `user` + INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` + INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`; + From cf0d36737f3548cec3da63a2d38e51957f2bd12c Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 15:18:34 +0000 Subject: [PATCH 13/30] Removed query for "updated" in gcontact --- src/Model/Item.php | 14 +++++++++++--- src/Model/Profile.php | 13 +++++-------- src/Module/NoScrape.php | 19 ++++--------------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index f6d08047b..bd8d03359 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2563,7 +2563,8 @@ class Item Contact::unmarkForArchival($contact); } - $update = (($arr['private'] != self::PRIVATE) && ((($arr['author-link'] ?? '') === ($arr['owner-link'] ?? '')) || ($arr["parent-uri"] === $arr["uri"]))); + /// @todo On private posts we could obfuscate the date + $update = ($arr['private'] != self::PRIVATE); // Is it a forum? Then we don't care about the rules from above if (!$update && in_array($arr["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN]) && ($arr["parent-uri"] === $arr["uri"])) { @@ -2573,8 +2574,15 @@ class Item } if ($update) { - DBA::update('contact', ['success_update' => $arr['received'], 'last-item' => $arr['received']], - ['id' => $arr['contact-id']]); + // The "self" contact id is used (for example in the connectors) when the contact is unknown + // So we have to ensure to only update the last item when it had been our own post, + // or it had been done by a "regular" contact. + if (!empty($arr['wall'])) { + $condition = ['id' => $arr['contact-id']]; + } else { + $condition = ['id' => $arr['contact-id'], 'self' => false]; + } + DBA::update('contact', ['success_update' => $arr['received'], 'last-item' => $arr['received']], $condition); } // Now do the same for the system wide contacts with uid=0 if ($arr['private'] != self::PRIVATE) { diff --git a/src/Model/Profile.php b/src/Model/Profile.php index ec862947b..4c877a906 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -398,18 +398,15 @@ class Profile $contact_block = ''; $updated = ''; $contact_count = 0; + + if (!empty($profile['last-item'])) { + $updated = date('c', strtotime($profile['last-item'])); + } + if (!$block) { $contact_block = ContactBlock::getHTML($a->profile); if (is_array($a->profile) && !$a->profile['hide-friends']) { - $r = q( - "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1", - intval($a->profile['uid']) - ); - if (DBA::isResult($r)) { - $updated = date('c', strtotime($r[0]['updated'])); - } - $contact_count = DBA::count('contact', [ 'uid' => $profile['uid'], 'self' => false, diff --git a/src/Module/NoScrape.php b/src/Module/NoScrape.php index a03770d0d..13a683d97 100644 --- a/src/Module/NoScrape.php +++ b/src/Module/NoScrape.php @@ -85,22 +85,11 @@ class NoScrape extends BaseModule $json_info['tags'] = $keywords; $json_info['language'] = $a->profile['language']; - if (!($a->profile['hide-friends'] ?? false)) { - $stmt = DBA::p( - "SELECT `gcontact`.`updated` - FROM `contact` - INNER JOIN `gcontact` - WHERE `gcontact`.`nurl` = `contact`.`nurl` - AND `self` - AND `uid` = ? - LIMIT 1", - intval($a->profile['uid']) - ); - if ($gcontact = DBA::fetch($stmt)) { - $json_info["updated"] = date("c", strtotime($gcontact['updated'])); - } - DBA::close($stmt); + if (!empty($a->profile['last-item'])) { + $json_info['updated'] = date("c", strtotime($a->profile['last-item'])); + } + if (!($a->profile['hide-friends'] ?? false)) { $json_info['contacts'] = DBA::count('contact', [ 'uid' => $a->profile['uid'], From 57009d30c480c7147ee6e5f02b2fe15cd98db7be Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 15:42:43 +0000 Subject: [PATCH 14/30] There is now a pending view --- src/Model/Register.php | 27 +++------------------------ static/dbview.config.php | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/Model/Register.php b/src/Model/Register.php index be00699bf..5eb9a417c 100644 --- a/src/Model/Register.php +++ b/src/Model/Register.php @@ -42,15 +42,7 @@ class Register */ public static function getPending($start = 0, $count = Pager::ITEMS_PER_PAGE) { - $stmt = DBA::p( - "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`, `contact`.`nick` - FROM `register` - INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` - INNER JOIN `user` ON `register`.`uid` = `user`.`uid` - LIMIT ?, ?", $start, $count - ); - - return DBA::toArray($stmt); + return DBA::selectToArray('pending-view', [], [], ['limit' => [$start, $count]]); } /** @@ -64,14 +56,7 @@ class Register */ public static function getPendingForUser(int $uid) { - return DBA::fetchFirst( - "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email` - FROM `register` - INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` - INNER JOIN `user` ON `register`.`uid` = `user`.`uid` - WHERE `register`.uid = ?", - $uid - ); + return DBA::selectToArray('pending-view', [], ['uid' => $uid]); } /** @@ -82,13 +67,7 @@ class Register */ public static function getPendingCount() { - $register = DBA::fetchFirst( - "SELECT COUNT(*) AS `count` - FROM `register` - INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` AND `contact`.`self`" - ); - - return $register['count']; + return DBA::count('pending-view', ['self' => true]); } /** diff --git a/static/dbview.config.php b/static/dbview.config.php index 4363c7886..9722ca381 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -174,6 +174,26 @@ return [ "query" => "FROM `user` INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`" - ] + ], + "pending-view" => [ + "fields" => [ + "id" => ["register", "id"], + "hash" => ["register", "hash"], + "created" => ["register", "created"], + "uid" => ["register", "uid"], + "password" => ["register", "password"], + "language" => ["register", "language"], + "note" => ["register", "note"], + "self" => ["contact", "self"], + "name" => ["contact", "name"], + "url" => ["contact", "url"], + "micro" => ["contact", "micro"], + "email" => ["user", "email"], + "nick" => ["contact", "nick"], + ], + "query" => "FROM `register` + INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` + INNER JOIN `user` ON `register`.`uid` = `user`.`uid`" + ], ]; From 749c2ce4ab31ef2a13747ccd12c61a0a4b422d4a Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 15:44:41 +0000 Subject: [PATCH 15/30] Updated database description --- database.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/database.sql b/database.sql index c7bd24f38..f5db49600 100644 --- a/database.sql +++ b/database.sql @@ -1523,4 +1523,26 @@ CREATE VIEW `owner-view` AS SELECT INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`; +-- +-- VIEW pending-view +-- +DROP VIEW IF EXISTS `pending-view`; +CREATE VIEW `pending-view` AS SELECT + `register`.`id` AS `id`, + `register`.`hash` AS `hash`, + `register`.`created` AS `created`, + `register`.`uid` AS `uid`, + `register`.`password` AS `password`, + `register`.`language` AS `language`, + `register`.`note` AS `note`, + `contact`.`self` AS `self`, + `contact`.`name` AS `name`, + `contact`.`url` AS `url`, + `contact`.`micro` AS `micro`, + `user`.`email` AS `email`, + `contact`.`nick` AS `nick` + FROM `register` + INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` + INNER JOIN `user` ON `register`.`uid` = `user`.`uid`; + From 89dcab774d6b6f88f43a07bff377184515dbec28 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 17:55:49 +0000 Subject: [PATCH 16/30] Prticipation is now a view as well --- src/Protocol/Diaspora.php | 21 ++++----------------- static/dbview.config.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 19ef391a0..fe6c328d9 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -259,27 +259,13 @@ class Diaspora */ public static function participantsForThread($thread, array $contacts) { - $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`network`, `contact`.`protocol`, - `fcontact`.`batch` AS `fbatch`, `fcontact`.`network` AS `fnetwork` FROM `participation` - INNER JOIN `contact` ON `contact`.`id` = `participation`.`cid` - INNER JOIN `fcontact` ON `fcontact`.`id` = `participation`.`fid` - WHERE `participation`.`iid` = ? AND NOT `contact`.`archive`", $thread); - - while ($contact = DBA::fetch($r)) { - if (!empty($contact['fnetwork'])) { - $contact['network'] = $contact['fnetwork']; - } - unset($contact['fnetwork']); + $participation = DBA::select('participation-view', [], ['iid' => $thread]); + while ($contact = DBA::fetch($participation)) { if (empty($contact['protocol'])) { $contact['protocol'] = $contact['network']; } - if (empty($contact['batch']) && !empty($contact['fbatch'])) { - $contact['batch'] = $contact['fbatch']; - } - unset($contact['fbatch']); - $exists = false; foreach ($contacts as $entry) { if ($entry['batch'] == $contact['batch']) { @@ -291,7 +277,8 @@ class Diaspora $contacts[] = $contact; } } - DBA::close($r); + + DBA::close($participation); return $contacts; } diff --git a/static/dbview.config.php b/static/dbview.config.php index 9722ca381..7e0ce0a0f 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -175,6 +175,20 @@ return [ INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`" ], + "participation-view" => [ + "fields" => [ + "iid" => ["participation", "iid"], + "id" => ["contact", "id"], + "url" => ["contact", "url"], + "name" => ["contact", "name"], + "protocol" => ["contact", "protocol"], + "batch" => "CASE `contact`.`batch` WHEN '' THEN `fcontact`.`batch` ELSE `contact`.`batch` END", + "network" => "CASE `fcontact`.`network` WHEN '' THEN `contact`.`network` ELSE `fcontact`.`network` END", + ], + "query" => "FROM `participation` + INNER JOIN `contact` ON `contact`.`id` = `participation`.`cid` AND NOT `contact`.`archive` + INNER JOIN `fcontact` ON `fcontact`.`id` = `participation`.`fid`" + ], "pending-view" => [ "fields" => [ "id" => ["register", "id"], From 1c980c5b29b464c335318c5acec9ad5678706882 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 18:50:36 +0000 Subject: [PATCH 17/30] The workerqueue is now using a view as well --- src/Core/Worker.php | 8 +++----- static/dbview.config.php | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Core/Worker.php b/src/Core/Worker.php index f41636bed..6fb8bd40f 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -684,7 +684,7 @@ class Worker self::$db_duration_stat += (microtime(true) - $stamp); while ($entry = DBA::fetch($jobs)) { $stamp = (float)microtime(true); - $processes = DBA::p("SELECT COUNT(*) AS `running` FROM `process` INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` WHERE NOT `done` AND `priority` = ?", $entry["priority"]); + $processes = DBA::p("SELECT COUNT(*) AS `running` FROM `workerqueue-view` WHERE `priority` = ?", $entry["priority"]); self::$db_duration += (microtime(true) - $stamp); self::$db_duration_stat += (microtime(true) - $stamp); if ($process = DBA::fetch($processes)) { @@ -698,7 +698,7 @@ class Worker } else { $waiting_processes = self::totalEntries(); $stamp = (float)microtime(true); - $jobs = DBA::p("SELECT COUNT(*) AS `running`, `priority` FROM `process` INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `done` GROUP BY `priority` ORDER BY `priority`"); + $jobs = DBA::p("SELECT COUNT(*) AS `running`, `priority` FROM `workerqueue-view` GROUP BY `priority` ORDER BY `priority`"); self::$db_duration += (microtime(true) - $stamp); self::$db_duration_stat += (microtime(true) - $stamp); @@ -839,9 +839,7 @@ class Worker $running = []; $running_total = 0; $stamp = (float)microtime(true); - $processes = DBA::p("SELECT COUNT(DISTINCT(`process`.`pid`)) AS `running`, `priority` FROM `process` - INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` - WHERE NOT `done` GROUP BY `priority`"); + $processes = DBA::p("SELECT COUNT(DISTINCT(`pid`)) AS `running`, `priority` FROM `workerqueue-view` GROUP BY `priority`"); self::$db_duration += (microtime(true) - $stamp); while ($process = DBA::fetch($processes)) { $running[$process['priority']] = $process['running']; diff --git a/static/dbview.config.php b/static/dbview.config.php index 7e0ce0a0f..715fb30cc 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -209,5 +209,14 @@ return [ INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` INNER JOIN `user` ON `register`.`uid` = `user`.`uid`" ], + "workerqueue-view" => [ + "fields" => [ + "pid" => ["process", "pid"], + "priority" => ["workerqueue", "priority"], + ], + "query" => "FROM `process` + INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` + WHERE NOT `workerqueue`.`done`" + ], ]; From ee3a724b41701ad4e87278abb69b4ffac6481183 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 20:39:14 +0000 Subject: [PATCH 18/30] Three more joins replaced with views --- src/Model/Profile.php | 69 +++++++++++++++------------------------ view/theme/vier/theme.php | 25 +++++++------- 2 files changed, 37 insertions(+), 57 deletions(-) diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 4c877a906..24db78a00 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -887,30 +887,25 @@ class Profile */ public static function searchProfiles($start = 0, $count = 100, $search = null) { - $publish = (DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1"); + $publish = (DI::config()->get('system', 'publish_all') ? 'true' : "`publish` = 1"); $total = 0; if (!empty($search)) { $searchTerm = '%' . $search . '%'; - $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` - FROM `profile` - LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` - WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` - AND ((`profile`.`name` LIKE ?) OR - (`user`.`nickname` LIKE ?) OR - (`profile`.`about` LIKE ?) OR - (`profile`.`locality` LIKE ?) OR - (`profile`.`region` LIKE ?) OR - (`profile`.`country-name` LIKE ?) OR - (`profile`.`pub_keywords` LIKE ?) OR - (`profile`.`prv_keywords` LIKE ?))", - $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, - $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm); + $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `owner-view` + WHERE $publish AND NOT `blocked` AND NOT `account_removed` + AND ((`name` LIKE ?) OR + (`nickname` LIKE ?) OR + (`about` LIKE ?) OR + (`locality` LIKE ?) OR + (`region` LIKE ?) OR + (`country-name` LIKE ?) OR + (`pub_keywords` LIKE ?) OR + (`prv_keywords` LIKE ?))", + $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm); } else { $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` - FROM `profile` - LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` - WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed`"); + FROM `owner-view` WHERE $publish AND NOT `blocked` AND NOT `account_removed`"); } if (DBA::isResult($cnt)) { @@ -925,35 +920,23 @@ class Profile if (!empty($search)) { $searchTerm = '%' . $search . '%'; - $profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`, - `contact`.`addr`, `contact`.`url` AS `profile_url` - FROM `profile` - LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` - LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid` - WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self` - AND ((`profile`.`name` LIKE ?) OR - (`user`.`nickname` LIKE ?) OR - (`profile`.`about` LIKE ?) OR - (`profile`.`locality` LIKE ?) OR - (`profile`.`region` LIKE ?) OR - (`profile`.`country-name` LIKE ?) OR - (`profile`.`pub_keywords` LIKE ?) OR - (`profile`.`prv_keywords` LIKE ?)) - $order LIMIT ?,?", + $profiles = DBA::p("SELECT * FROM `owner-view` + WHERE $publish AND NOT `blocked` AND NOT `account_removed` + AND ((`name` LIKE ?) OR + (`nickname` LIKE ?) OR + (`about` LIKE ?) OR + (`locality` LIKE ?) OR + (`region` LIKE ?) OR + (`country-name` LIKE ?) OR + (`pub_keywords` LIKE ?) OR + (`prv_keywords` LIKE ?)) + $order LIMIT ?,?", $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, - $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $start, $count ); } else { - $profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`, - `contact`.`addr`, `contact`.`url` AS `profile_url` - FROM `profile` - LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` - LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid` - WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self` - $order LIMIT ?,?", - $start, $count - ); + $profiles = DBA::p("SELECT * FROM `owner-view` + WHERE $publish AND NOT `blocked` AND NOT `account_removed` $order LIMIT ?,?", $start, $count); } } diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index fcbb148dc..cc3a668e6 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -140,29 +140,26 @@ function vier_community_info() // last 9 users if ($show_lastusers) { - $publish = (DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1"); - $order = " ORDER BY `register_date` DESC "; + $condition = ['blocked' => false]; + if (!DI::config()->get('system', 'publish_all')) { + $condition['publish'] = true; + } $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl'); - $r = q("SELECT `profile`.*, `user`.`nickname` - FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` - WHERE $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ", - 0, - 9 - ); + $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]); - if (DBA::isResult($r)) { + if (DBA::isResult($profiles)) { $aside['$lastusers_title'] = DI::l10n()->t('Last users'); $aside['$lastusers_items'] = []; - foreach ($r as $rr) { - $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['uid']); + foreach ($profiles as $profile) { + $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']); $entry = Renderer::replaceMacros($tpl, [ - '$id' => $rr['id'], + '$id' => $profile['id'], '$profile_link' => $profile_link, - '$photo' => DI::baseUrl()->remove($rr['thumb']), - '$alt_text' => $rr['name']]); + '$photo' => DI::baseUrl()->remove($profile['thumb']), + '$alt_text' => $profile['name']]); $aside['$lastusers_items'][] = $entry; } } From efa1351ac62abd1f1040336894aa7ea112e96ea8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Apr 2020 21:14:03 +0000 Subject: [PATCH 19/30] Cleaned up user table order in query --- static/dbview.config.php | 41 +++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/static/dbview.config.php b/static/dbview.config.php index 715fb30cc..20da1b2d4 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -133,30 +133,45 @@ return [ "notify_new_posts" => ["notify_new_posts"], "fetch_further_information" => ["fetch_further_information"], "ffi_keyword_blacklist" => ["ffi_keyword_blacklist"], + "parent-uid" => ["user", "parent-uid"], "guid" => ["user", "guid"], - "theme" => ["user", "theme"], - "language" => ["user", "language"], - "email" => ["user", "email"], - "uprvkey" => ["user", "prvkey"], - "upubkey" => ["user", "pubkey"], - "timezone" => ["user", "timezone"], - "nickname" => ["user", "nickname"], /// @todo Replaces all uses of "nickname" with "nick" "username" => ["user", "username"], /// @todo Replaces all uses of "username" with "name" + "nickname" => ["user", "nickname"], /// @todo Replaces all uses of "nickname" with "nick" + "email" => ["user", "email"], + "openid" => ["user", "openid"], + "timezone" => ["user", "timezone"], + "language" => ["user", "language"], + "register_date" => ["user", "register_date"], + "login_date" => ["user", "login_date"], + "default-location" => ["user", "default-location"], + "allow_location" => ["user", "allow_location"], + "theme" => ["user", "theme"], + "upubkey" => ["user", "pubkey"], + "uprvkey" => ["user", "prvkey"], "sprvkey" => ["user", "sprvkey"], "spubkey" => ["user", "spubkey"], + "verified" => ["user", "verified"], + "blockwall" => ["user", "blockwall"], + "hidewall" => ["user", "hidewall"], + "blocktags" => ["user", "blocktags"], + "unkmail" => ["user", "unkmail"], + "cntunkmail" => ["user", "cntunkmail"], + "notify-flags" => ["user", "notify-flags"], "page-flags" => ["user", "page-flags"], "account-type" => ["user", "account-type"], "prvnets" => ["user", "prvnets"], - "account_removed" => ["user", "account_removed"], - "hidewall" => ["user", "hidewall"], - "login_date" => ["user", "login_date"], - "register_date" => ["user", "register_date"], - "verified" => ["user", "verified"], + "maxreq" => ["user", "maxreq"], "expire" => ["user", "expire"], - "expire_notification_sent" => ["user", "expire_notification_sent"], "account_removed" => ["user", "account_removed"], "account_expired" => ["user", "account_expired"], "account_expires_on" => ["user", "account_expires_on"], + "expire_notification_sent" => ["user", "expire_notification_sent"], + "def_gid" => ["user", "def_gid"], + "allow_cid" => ["user", "allow_cid"], + "allow_gid" => ["user", "allow_gid"], + "deny_cid" => ["user", "deny_cid"], + "deny_gid" => ["user", "deny_gid"], + "openidserver" => ["user", "openidserver"], "publish" => ["profile", "publish"], "net-publish" => ["profile", "net-publish"], "hide-friends" => ["profile", "hide-friends"], From 7d111e2a6fc7cb5e2d70d8e6e2da1f4cadc51c7b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 25 Apr 2020 07:29:02 +0000 Subject: [PATCH 20/30] Duplicated fields renamed --- src/Console/User.php | 2 +- src/Module/Admin/Users.php | 4 ++-- src/Module/Profile/Profile.php | 8 ++++---- src/Module/Profile/Status.php | 10 +++++----- src/Protocol/Salmon.php | 6 +++--- static/dbview.config.php | 5 +---- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index b12a3a6ad..d97662038 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -361,7 +361,7 @@ HELP; $contact['email'], Temporal::getRelativeDate($contact['created']), Temporal::getRelativeDate($contact['login_date']), - Temporal::getRelativeDate($contact['lastitem_date']), + Temporal::getRelativeDate($contact['last-item']), ]); } $this->out($table->getTable()); diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 822ac0c01..002e6c5fe 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -161,7 +161,7 @@ class Users extends BaseAdmin 'email', 'register_date', 'login_date', - 'lastitem_date', + 'last-item', 'page-flags' ]; @@ -206,7 +206,7 @@ class Users extends BaseAdmin $e['register_date'] = Temporal::getRelativeDate($e['register_date']); $e['login_date'] = Temporal::getRelativeDate($e['login_date']); - $e['lastitem_date'] = Temporal::getRelativeDate($e['lastitem_date']); + $e['last-item'] = Temporal::getRelativeDate($e['last-item']); $e['is_admin'] = in_array($e['email'], $adminlist); $e['is_deletable'] = (intval($e['uid']) != local_user()); $e['deleted'] = ($e['account_removed'] ? Temporal::getRelativeDate($e['account_expires_on']) : False); diff --git a/src/Module/Profile/Profile.php b/src/Module/Profile/Profile.php index 614264880..6c7f4f14e 100644 --- a/src/Module/Profile/Profile.php +++ b/src/Module/Profile/Profile.php @@ -299,10 +299,10 @@ class Profile extends BaseProfile $htmlhead .= '' . "\n"; } - $htmlhead .= '' . "\n"; - $htmlhead .= '' . "\n"; - $htmlhead .= '' . "\n"; - $htmlhead .= '' . "\n"; + $htmlhead .= '' . "\n"; + $htmlhead .= '' . "\n"; + $htmlhead .= '' . "\n"; + $htmlhead .= '' . "\n"; $uri = urlencode('acct:' . $profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : '')); $htmlhead .= '' . "\n"; header('Link: <' . $baseUrl . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); diff --git a/src/Module/Profile/Status.php b/src/Module/Profile/Status.php index bb19be2b9..8b6734e5c 100644 --- a/src/Module/Profile/Status.php +++ b/src/Module/Profile/Status.php @@ -53,10 +53,10 @@ class Status extends BaseProfile DI::page()['htmlhead'] .= '' . "\n"; } - DI::page()['htmlhead'] .= '' . "\n"; - DI::page()['htmlhead'] .= '' . "\n"; - DI::page()['htmlhead'] .= '' . "\n"; - DI::page()['htmlhead'] .= '' . "\n"; + DI::page()['htmlhead'] .= '' . "\n"; + DI::page()['htmlhead'] .= '' . "\n"; + DI::page()['htmlhead'] .= '' . "\n"; + DI::page()['htmlhead'] .= '' . "\n"; $category = $datequery = $datequery2 = ''; @@ -162,7 +162,7 @@ class Status extends BaseProfile // If not then we can improve the performance with an additional condition $condition = ['uid' => $a->profile['uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]]; if (!DBA::exists('user', $condition)) { - $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['contact_id']))); + $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['id']))); } else { $sql_extra3 = ""; } diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index 0d234b53f..d082909ae 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -111,13 +111,13 @@ class Salmon { // does contact have a salmon endpoint? - if (! strlen($url)) { + if (!strlen($url)) { return; } - if (! $owner['sprvkey']) { + if (!$owner['sprvkey']) { Logger::log(sprintf("user '%s' (%d) does not have a salmon private key. Send failed.", - $owner['username'], $owner['uid'])); + $owner['name'], $owner['uid'])); return; } diff --git a/static/dbview.config.php b/static/dbview.config.php index 20da1b2d4..1d95261a2 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -103,11 +103,9 @@ return [ "name-date" => ["contact", "name-date"], "uri-date" => ["contact", "uri-date"], "avatar-date" => ["contact", "avatar-date"], - "contact_id" => ["contact", "id"], /// @todo Replaces all uses of "contact_id" with "id" "picdate" => ["contact", "avatar-date"], /// @todo Replaces all uses of "picdate" with "avatar-date" "term-date" => ["contact", "term-date"], - "last-item" => ["contact", "last-item"], - "lastitem_date" => ["contact", "last-item"], /// @todo Replaces all uses of "lastitem_date" with "last-item" + "last-item" => ["contact", "last-item"], "priority" => ["contact", "priority"], "blocked" => ["contact", "blocked"], /// @todo Check if "blocked" from contact or from the users table "block_reason" => ["contact", "block_reason"], @@ -135,7 +133,6 @@ return [ "ffi_keyword_blacklist" => ["ffi_keyword_blacklist"], "parent-uid" => ["user", "parent-uid"], "guid" => ["user", "guid"], - "username" => ["user", "username"], /// @todo Replaces all uses of "username" with "name" "nickname" => ["user", "nickname"], /// @todo Replaces all uses of "nickname" with "nick" "email" => ["user", "email"], "openid" => ["user", "openid"], From e012730e52084f5917c7196ddd015e66d6e2061d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 25 Apr 2020 07:29:38 +0000 Subject: [PATCH 21/30] Added check and repair for missing self contact --- src/Model/User.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Model/User.php b/src/Model/User.php index e7f2f89ad..be71bcf64 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -197,7 +197,11 @@ class User { $owner = DBA::selectFirst('owner-view', [], ['uid' => $uid]); if (!DBA::isResult($owner)) { - return false; + if (!DBA::exists('user', ['uid' => $uid]) || !$check_valid) { + return false; + } + Contact::createSelfFromUserId($uid); + $owner = self::getOwnerDataById($uid, false); } if (empty($owner['nickname'])) { From 51bc5279a07397e28b35fbeefb27ea6041f9b6cd Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 25 Apr 2020 18:36:58 +0000 Subject: [PATCH 22/30] Documentation and unneeded stuff removed --- src/Database/DBStructure.php | 2 +- src/Database/View.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 1433a5346..dc13bd656 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -117,7 +117,7 @@ class DBStructure } /** - * Loads the database structure definition from the config/dbstructure.config.php file. + * Loads the database structure definition from the static/dbstructure.config.php file. * On first pass, defines DB_UPDATE_VERSION constant. * * @see static/dbstructure.config.php diff --git a/src/Database/View.php b/src/Database/View.php index fa4c502a2..c7f55ee75 100644 --- a/src/Database/View.php +++ b/src/Database/View.php @@ -25,8 +25,6 @@ use Exception; use Friendica\Core\Hook; use Friendica\DI; -require_once __DIR__ . '/../../include/dba.php'; - class View { /** @@ -37,7 +35,7 @@ class View private static $definition = []; /** - * Loads the database structure definition from the config/dbview.config.php file. + * Loads the database structure definition from the static/dbview.config.php file. * On first pass, defines DB_UPDATE_VERSION constant. * * @see static/dbview.config.php From 7f17c1484a2529f5561e2c74d51d66fbd6ee9aa6 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 25 Apr 2020 23:33:01 +0200 Subject: [PATCH 23/30] Update src/Model/Profile.php Co-Authored-By: Hypolite Petovan --- src/Model/Profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 24db78a00..dc7e02642 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -887,7 +887,7 @@ class Profile */ public static function searchProfiles($start = 0, $count = 100, $search = null) { - $publish = (DI::config()->get('system', 'publish_all') ? 'true' : "`publish` = 1"); + $publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` = 1"); $total = 0; if (!empty($search)) { From 37b9031a27e0627a942d6a73a075418ca086b755 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 25 Apr 2020 23:33:11 +0200 Subject: [PATCH 24/30] Update src/Model/Profile.php Co-Authored-By: Hypolite Petovan --- src/Model/Profile.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Model/Profile.php b/src/Model/Profile.php index dc7e02642..d83402410 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -936,7 +936,13 @@ class Profile ); } else { $profiles = DBA::p("SELECT * FROM `owner-view` - WHERE $publish AND NOT `blocked` AND NOT `account_removed` $order LIMIT ?,?", $start, $count); + WHERE NOT `blocked` AND NOT `account_removed` + $publish + $order + LIMIT ?, ?", + $start, + $count + ); } } From 3f9c78a20bb325983fe7f1823e38884d6a63a314 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 26 Apr 2020 08:04:03 +0200 Subject: [PATCH 25/30] Update src/Model/Profile.php Co-Authored-By: Hypolite Petovan --- src/Model/Profile.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Model/Profile.php b/src/Model/Profile.php index d83402410..261c7cc22 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -893,7 +893,8 @@ class Profile if (!empty($search)) { $searchTerm = '%' . $search . '%'; $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `owner-view` - WHERE $publish AND NOT `blocked` AND NOT `account_removed` + WHERE NOT `blocked` AND NOT `account_removed` + $publish AND ((`name` LIKE ?) OR (`nickname` LIKE ?) OR (`about` LIKE ?) OR From 3107680e51b0b1fdbcd5fb810574f797e13241a1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 26 Apr 2020 08:04:17 +0200 Subject: [PATCH 26/30] Update src/Model/Profile.php Co-Authored-By: Hypolite Petovan --- src/Model/Profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 261c7cc22..9311df83b 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -906,7 +906,7 @@ class Profile $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm); } else { $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` - FROM `owner-view` WHERE $publish AND NOT `blocked` AND NOT `account_removed`"); + FROM `owner-view` WHERE NOT `blocked` AND NOT `account_removed` $publish"); } if (DBA::isResult($cnt)) { From 7e8bcc903401e8fb4b014ba0a58a7db1d655a054 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 26 Apr 2020 08:04:34 +0200 Subject: [PATCH 27/30] Update src/Model/Profile.php Co-Authored-By: Hypolite Petovan --- src/Model/Profile.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 9311df83b..e53474123 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -922,7 +922,8 @@ class Profile $searchTerm = '%' . $search . '%'; $profiles = DBA::p("SELECT * FROM `owner-view` - WHERE $publish AND NOT `blocked` AND NOT `account_removed` + WHERE NOT `blocked` AND NOT `account_removed` + $publish AND ((`name` LIKE ?) OR (`nickname` LIKE ?) OR (`about` LIKE ?) OR From d74067b4613d934d297570c1c1bbf2f32f5fc6c2 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Apr 2020 06:58:30 +0000 Subject: [PATCH 28/30] Queries had been simplified --- src/Model/Profile.php | 69 +++++++++---------------------------------- 1 file changed, 14 insertions(+), 55 deletions(-) diff --git a/src/Model/Profile.php b/src/Model/Profile.php index e53474123..348e16bad 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -887,13 +887,10 @@ class Profile */ public static function searchProfiles($start = 0, $count = 100, $search = null) { - $publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` = 1"); - $total = 0; - if (!empty($search)) { + $publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` "); $searchTerm = '%' . $search . '%'; - $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `owner-view` - WHERE NOT `blocked` AND NOT `account_removed` + $condition = ["NOT `blocked` AND NOT `account_removed` $publish AND ((`name` LIKE ?) OR (`nickname` LIKE ?) OR @@ -903,62 +900,24 @@ class Profile (`country-name` LIKE ?) OR (`pub_keywords` LIKE ?) OR (`prv_keywords` LIKE ?))", - $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm); + $searchTerm, $searchTerm, $searchTerm, $searchTerm, + $searchTerm, $searchTerm, $searchTerm, $searchTerm]; } else { - $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` - FROM `owner-view` WHERE NOT `blocked` AND NOT `account_removed` $publish"); - } - - if (DBA::isResult($cnt)) { - $total = $cnt['total']; - } - - $order = " ORDER BY `name` ASC "; - $profiles = []; - - // If nothing found, don't try to select details - if ($total > 0) { - if (!empty($search)) { - $searchTerm = '%' . $search . '%'; - - $profiles = DBA::p("SELECT * FROM `owner-view` - WHERE NOT `blocked` AND NOT `account_removed` - $publish - AND ((`name` LIKE ?) OR - (`nickname` LIKE ?) OR - (`about` LIKE ?) OR - (`locality` LIKE ?) OR - (`region` LIKE ?) OR - (`country-name` LIKE ?) OR - (`pub_keywords` LIKE ?) OR - (`prv_keywords` LIKE ?)) - $order LIMIT ?,?", - $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, - $start, $count - ); - } else { - $profiles = DBA::p("SELECT * FROM `owner-view` - WHERE NOT `blocked` AND NOT `account_removed` - $publish - $order - LIMIT ?, ?", - $start, - $count - ); + $condition = ['blocked' => false, 'account_removed' => false]; + if (!DI::config()->get('system', 'publish_all')) { + $condition['publish'] = true; } } - if (DBA::isResult($profiles) && $total > 0) { - return [ - 'total' => $total, - 'entries' => DBA::toArray($profiles), - ]; + $total = DBA::count('owner-view', $condition); + // If nothing found, don't try to select details + if ($total > 0) { + $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['name'], 'limit' => [$start, $count]]); } else { - return [ - 'total' => $total, - 'entries' => [], - ]; + $profiles = []; } + + return ['total' => $total, 'entries' => $profiles]; } } From 6c59e0380593c7dd5dbe41024aa21159999d85fa Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Apr 2020 16:20:17 +0000 Subject: [PATCH 29/30] Renamed comment --- src/Database/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/View.php b/src/Database/View.php index c7f55ee75..e1335d9df 100644 --- a/src/Database/View.php +++ b/src/Database/View.php @@ -28,7 +28,7 @@ use Friendica\DI; class View { /** - * view definition loaded from config/dbview.config.php + * view definition loaded from static/dbview.config.php * * @var array */ From 53b0401d6adf4230a2b44f4547d406911e1b7bdd Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Apr 2020 16:25:46 +0000 Subject: [PATCH 30/30] Fix tests - hopefully --- tests/datasets/api.fixture.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 8bb701da1..c9c16a33f 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -256,6 +256,12 @@ return [ 'wall' => 1, ], ], + 'profile' => [ + [ + 'id' => 1, + 'uid' => 42, + ], + ], 'group' => [ [ 'id' => 1,