From 24b5396b1d1e0c63b6dcc4d6d0ab7b73fb9d4cd8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Aug 2020 11:31:34 +0000 Subject: [PATCH 1/5] Using a view for the network page --- database.sql | 61 ++++++++++++++++++++++++++- mod/network.php | 78 +++++++++++++---------------------- static/dbstructure.config.php | 2 +- static/dbview.config.php | 55 ++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 51 deletions(-) diff --git a/database.sql b/database.sql index 59320fe872..3236870f37 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2020.09-dev (Red Hot Poker) --- DB_UPDATE_VERSION 1359 +-- DB_UPDATE_VERSION 1360 -- ------------------------------------------ @@ -1388,6 +1388,65 @@ 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 network-thread-view +-- +DROP VIEW IF EXISTS `network-thread-view`; +CREATE VIEW `network-thread-view` AS SELECT + `item`.`uri-id` AS `uri-id`, + `item`.`uri` AS `uri`, + `item`.`parent-uri-id` AS `parent-uri-id`, + `thread`.`iid` AS `parent`, + `thread`.`iid` AS `item_id`, + `thread`.`received` AS `received`, + `thread`.`commented` AS `commented`, + `thread`.`created` AS `created`, + `thread`.`uid` AS `uid`, + `thread`.`starred` AS `starred`, + `thread`.`mention` AS `mention`, + `thread`.`network` AS `network`, + `thread`.`contact-id` AS `contact-id` + FROM `thread` + STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`) + STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid` + LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid` + LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id` + LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id` + WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` + AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) + AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) + AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`); + +-- +-- VIEW network-item-view +-- +DROP VIEW IF EXISTS `network-item-view`; +CREATE VIEW `network-item-view` AS SELECT + `item`.`parent-uri-id` AS `uri-id`, + `item`.`parent-uri` AS `uri`, + `item`.`parent` AS `parent`, + `item`.`parent` AS `item_id`, + `item`.`received` AS `received`, + `item`.`commented` AS `commented`, + `item`.`created` AS `created`, + `item`.`uid` AS `uid`, + `item`.`starred` AS `starred`, + `item`.`mention` AS `mention`, + `item`.`network` AS `network`, + `item`.`unseen` AS `unseen`, + `item`.`gravity` AS `gravity`, + `item`.`contact-id` AS `contact-id` + FROM `item` + INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent` + STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`) + LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid` + LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id` + LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id` + WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` + AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) + AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) + AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`); + -- -- VIEW owner-view -- diff --git a/mod/network.php b/mod/network.php index b493f7770c..0002743ab0 100644 --- a/mod/network.php +++ b/mod/network.php @@ -499,19 +499,24 @@ function networkThreadedView(App $a, $update, $parent) $o .= status_editor($a, $x); } - $sql_table = $update ? '`item`' : '`thread`'; + $condition1 = ['uid' => local_user()]; + $condition2 = []; - $sql_extra = ($star ? " AND `thread`.`starred` " : '') . - ($conv ? " AND $sql_table.`mention`" : '') . - ($nets ? sprintf(" AND $sql_table.`network` = '%s' ", DBA::escape($nets)) : ''); + if ($star) { + $condition1['starred'] = true; + } + if ($conv) { + $condition1['mention'] = true; + } + if ($nets) { + $condition1['network'] = $nets; + } if ($datequery) { - $sql_extra .= Strings::protectSprintf(sprintf(" AND $sql_table.received <= '%s' ", - DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())))); + $condition2 = DBA::mergeConditions($condition2, ["`received` <= ? ", DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())]); } if ($datequery2) { - $sql_extra .= Strings::protectSprintf(sprintf(" AND $sql_table.received >= '%s' ", - DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())))); + $condition2 = DBA::mergeConditions($condition2, ["`received` >= ? ", DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())]); } if ($gid) { @@ -525,7 +530,7 @@ function networkThreadedView(App $a, $update, $parent) // NOTREACHED } - $sql_extra .= sprintf(" AND `thread`.`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = %d) ", intval($gid)); + $condition2 = DBA::mergeConditions($condition2, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $gid]); $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [ '$title' => DI::l10n()->t('Group: %s', $group['name']) @@ -533,7 +538,7 @@ function networkThreadedView(App $a, $update, $parent) } elseif ($cid) { $contact = Contact::getById($cid); if (DBA::isResult($contact)) { - $sql_extra .= " AND " . $sql_table . ".`contact-id` = " . intval($cid); + $condition1['contact-id'] = $cid; $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [ 'contacts' => [ModuleContact::getContactTemplateVars($contact)], @@ -558,8 +563,6 @@ function networkThreadedView(App $a, $update, $parent) $order_mode = 'commented'; } - $sql_order = "$sql_table.$ordering"; - $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); networkPager($a, $pager); @@ -572,22 +575,22 @@ function networkThreadedView(App $a, $update, $parent) switch ($order_mode) { case 'received': if ($last_received != '') { - $sql_extra .= sprintf(" AND $sql_table.`received` < '%s'", DBA::escape($last_received)); + $condition2 = DBA::mergeConditions($condition2, ["`received` < ?", $last_received]); } break; case 'commented': if ($last_commented != '') { - $sql_extra .= sprintf(" AND $sql_table.`commented` < '%s'", DBA::escape($last_commented)); + $condition2 = DBA::mergeConditions($condition2, ["`commented` < ?", $last_commented]); } break; case 'created': if ($last_created != '') { - $sql_extra .= sprintf(" AND $sql_table.`created` < '%s'", DBA::escape($last_created)); + $condition2 = DBA::mergeConditions($condition2, ["`created` < ?", $last_created]); } break; case 'uriid': if ($last_uriid > 0) { - $sql_extra .= sprintf(" AND $sql_table.`uri-id` < '%s'", DBA::escape($last_uriid)); + $condition2 = DBA::mergeConditions($condition2, ["`uri-id` < ?", $last_uriid]); } break; } @@ -596,46 +599,23 @@ function networkThreadedView(App $a, $update, $parent) if ($update) { if (!empty($parent)) { // Load only a single thread - $sql_extra2 = "`item`.`id` = ".intval($parent); + $condition1['id'] = $parent; } elseif ($order === 'post') { // Only load new toplevel posts - $sql_extra2 = "`item`.`unseen` AND `item`.`gravity` = " . GRAVITY_PARENT; + $condition1['unseen'] = true; + $condition1['gravity'] = GRAVITY_PARENT; } else { // Load all unseen items - $sql_extra2 = "`item`.`unseen`"; + $condition1['unseen'] = true; } - $r = q("SELECT `item`.`parent-uri` AS `uri`, `item`.`parent` AS `item_id`, $sql_order AS `order_date` - FROM `item` - INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent` - STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` - AND (NOT `contact`.`blocked` OR `contact`.`pending`) - LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d - WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted` - AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) - AND NOT `thread`.`moderated` AND $sql_extra2 - $sql_extra - ORDER BY `order_date` DESC LIMIT 100", - intval(local_user()), - intval(local_user()) - ); + $condition = DBA::mergeConditions($condition1, $condition2); + $params = ['order' => [$order_mode => true], 'limit' => 100]; + $r = DBA::selectToArray('network-item-view', [], $condition, $params); } else { - $r = q("SELECT `item`.`uri`, `thread`.`iid` AS `item_id`, $sql_order AS `order_date` - FROM `thread` - STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` - AND (NOT `contact`.`blocked` OR `contact`.`pending`) - STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid` - LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d - WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted` - AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) - AND NOT `thread`.`moderated` - $sql_extra - ORDER BY `order_date` DESC LIMIT %d, %d", - intval(local_user()), - intval(local_user()), - intval($pager->getStart()), - intval($pager->getItemsPerPage()) - ); + $condition = DBA::mergeConditions($condition1, $condition2); + $params = ['order' => [$order_mode => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; + $r = DBA::selectToArray('network-thread-view', [], $condition, $params); } return $o . network_display_post($a, $pager, (!$gid && !$cid && !$star), $update, $ordering, $r); diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index e9232f0724..aa1552f9c0 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', 1359); + define('DB_UPDATE_VERSION', 1360); } return [ diff --git a/static/dbview.config.php b/static/dbview.config.php index 47bf970900..50cd2a1e5a 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -68,6 +68,61 @@ return [ LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id` LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`" ], + "network-thread-view" => [ + "fields" => [ + "uri-id" => ["item", "uri-id"], + "uri" => ["item", "uri"], + "parent-uri-id" => ["item", "parent-uri-id"], + "parent" => ["thread", "iid"], + "item_id" => ["thread", "iid"], + "received" => ["thread", "received"], + "commented" => ["thread", "commented"], + "created" => ["thread", "created"], + "uid" => ["thread", "uid"], + "starred" => ["thread", "starred"], + "mention" => ["thread", "mention"], + "network" => ["thread", "network"], + "contact-id" => ["thread", "contact-id"], + ], + "query" => "FROM `thread` + STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`) + STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid` + LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid` + LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id` + LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id` + WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` + AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) + AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) + AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`)" + ], + "network-item-view" => [ + "fields" => [ + "uri-id" => ["item", "parent-uri-id"], + "uri" => ["item", "parent-uri"], + "parent" => ["item", "parent"], + "item_id" => ["item", "parent"], + "received" => ["item", "received"], + "commented" => ["item", "commented"], + "created" => ["item", "created"], + "uid" => ["item", "uid"], + "starred" => ["item", "starred"], + "mention" => ["item", "mention"], + "network" => ["item", "network"], + "unseen" => ["item", "unseen"], + "gravity" => ["item", "gravity"], + "contact-id" => ["item", "contact-id"], + ], + "query" => "FROM `item` + INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent` + STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`) + LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid` + LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id` + LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id` + WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` + AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) + AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) + AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`)" + ], "owner-view" => [ "fields" => [ "id" => ["contact", "id"], From 17bc81d36edc6fe735b68802c8e76d18bcf6c30b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Aug 2020 11:47:11 +0000 Subject: [PATCH 2/5] Simplifying the code --- mod/network.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mod/network.php b/mod/network.php index 0002743ab0..0ec975ed42 100644 --- a/mod/network.php +++ b/mod/network.php @@ -609,14 +609,11 @@ function networkThreadedView(App $a, $update, $parent) $condition1['unseen'] = true; } - $condition = DBA::mergeConditions($condition1, $condition2); $params = ['order' => [$order_mode => true], 'limit' => 100]; - $r = DBA::selectToArray('network-item-view', [], $condition, $params); } else { - $condition = DBA::mergeConditions($condition1, $condition2); $params = ['order' => [$order_mode => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; - $r = DBA::selectToArray('network-thread-view', [], $condition, $params); } + $r = DBA::selectToArray('network-item-view', [], DBA::mergeConditions($condition1, $condition2), $params); return $o . network_display_post($a, $pager, (!$gid && !$cid && !$star), $update, $ordering, $r); } From d46359a891fee503ef9ebe3a6d2821a7c037d2a3 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Aug 2020 11:54:37 +0000 Subject: [PATCH 3/5] Use the correct table --- mod/network.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mod/network.php b/mod/network.php index 0ec975ed42..59597102f9 100644 --- a/mod/network.php +++ b/mod/network.php @@ -610,10 +610,12 @@ function networkThreadedView(App $a, $update, $parent) } $params = ['order' => [$order_mode => true], 'limit' => 100]; + $table = 'network-item-view'; } else { $params = ['order' => [$order_mode => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; + $table = 'network-thread-view'; } - $r = DBA::selectToArray('network-item-view', [], DBA::mergeConditions($condition1, $condition2), $params); + $r = DBA::selectToArray($table, [], DBA::mergeConditions($condition1, $condition2), $params); return $o . network_display_post($a, $pager, (!$gid && !$cid && !$star), $update, $ordering, $r); } From 71d9037970c3bfc5366a99ff0752cd1a8a7bbd98 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Aug 2020 12:06:18 +0000 Subject: [PATCH 4/5] Some further cleaning up --- database.sql | 58 +++++++++++++++++++--------------------- mod/network.php | 4 +-- static/dbview.config.php | 54 ++++++++++++++++++------------------- 3 files changed, 56 insertions(+), 60 deletions(-) diff --git a/database.sql b/database.sql index 3236870f37..5387d14c6c 100644 --- a/database.sql +++ b/database.sql @@ -1388,35 +1388,6 @@ 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 network-thread-view --- -DROP VIEW IF EXISTS `network-thread-view`; -CREATE VIEW `network-thread-view` AS SELECT - `item`.`uri-id` AS `uri-id`, - `item`.`uri` AS `uri`, - `item`.`parent-uri-id` AS `parent-uri-id`, - `thread`.`iid` AS `parent`, - `thread`.`iid` AS `item_id`, - `thread`.`received` AS `received`, - `thread`.`commented` AS `commented`, - `thread`.`created` AS `created`, - `thread`.`uid` AS `uid`, - `thread`.`starred` AS `starred`, - `thread`.`mention` AS `mention`, - `thread`.`network` AS `network`, - `thread`.`contact-id` AS `contact-id` - FROM `thread` - STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`) - STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid` - LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid` - LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id` - LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id` - WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` - AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) - AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) - AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`); - -- -- VIEW network-item-view -- @@ -1425,7 +1396,6 @@ CREATE VIEW `network-item-view` AS SELECT `item`.`parent-uri-id` AS `uri-id`, `item`.`parent-uri` AS `uri`, `item`.`parent` AS `parent`, - `item`.`parent` AS `item_id`, `item`.`received` AS `received`, `item`.`commented` AS `commented`, `item`.`created` AS `created`, @@ -1447,6 +1417,34 @@ CREATE VIEW `network-item-view` AS SELECT AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`); +-- +-- VIEW network-thread-view +-- +DROP VIEW IF EXISTS `network-thread-view`; +CREATE VIEW `network-thread-view` AS SELECT + `item`.`uri-id` AS `uri-id`, + `item`.`uri` AS `uri`, + `item`.`parent-uri-id` AS `parent-uri-id`, + `thread`.`iid` AS `parent`, + `thread`.`received` AS `received`, + `thread`.`commented` AS `commented`, + `thread`.`created` AS `created`, + `thread`.`uid` AS `uid`, + `thread`.`starred` AS `starred`, + `thread`.`mention` AS `mention`, + `thread`.`network` AS `network`, + `thread`.`contact-id` AS `contact-id` + FROM `thread` + STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`) + STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid` + LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid` + LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id` + LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id` + WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` + AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) + AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) + AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`); + -- -- VIEW owner-view -- diff --git a/mod/network.php b/mod/network.php index 59597102f9..6a7b8db5f7 100644 --- a/mod/network.php +++ b/mod/network.php @@ -628,8 +628,8 @@ function network_display_post($a, $pager, $mark_all, $update, $ordering, $items) $parents_arr = []; foreach ($items as $item) { - if (!in_array($item['item_id'], $parents_arr) && ($item['item_id'] > 0)) { - $parents_arr[] = $item['item_id']; + if (!in_array($item['parent'], $parents_arr) && ($item['parent'] > 0)) { + $parents_arr[] = $item['parent']; } } $parents_str = implode(', ', $parents_arr); diff --git a/static/dbview.config.php b/static/dbview.config.php index 50cd2a1e5a..55cfd0155e 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -68,39 +68,11 @@ return [ LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id` LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`" ], - "network-thread-view" => [ - "fields" => [ - "uri-id" => ["item", "uri-id"], - "uri" => ["item", "uri"], - "parent-uri-id" => ["item", "parent-uri-id"], - "parent" => ["thread", "iid"], - "item_id" => ["thread", "iid"], - "received" => ["thread", "received"], - "commented" => ["thread", "commented"], - "created" => ["thread", "created"], - "uid" => ["thread", "uid"], - "starred" => ["thread", "starred"], - "mention" => ["thread", "mention"], - "network" => ["thread", "network"], - "contact-id" => ["thread", "contact-id"], - ], - "query" => "FROM `thread` - STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`) - STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid` - LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid` - LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id` - LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id` - WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` - AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) - AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) - AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`)" - ], "network-item-view" => [ "fields" => [ "uri-id" => ["item", "parent-uri-id"], "uri" => ["item", "parent-uri"], "parent" => ["item", "parent"], - "item_id" => ["item", "parent"], "received" => ["item", "received"], "commented" => ["item", "commented"], "created" => ["item", "created"], @@ -123,6 +95,32 @@ return [ AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`)" ], + "network-thread-view" => [ + "fields" => [ + "uri-id" => ["item", "uri-id"], + "uri" => ["item", "uri"], + "parent-uri-id" => ["item", "parent-uri-id"], + "parent" => ["thread", "iid"], + "received" => ["thread", "received"], + "commented" => ["thread", "commented"], + "created" => ["thread", "created"], + "uid" => ["thread", "uid"], + "starred" => ["thread", "starred"], + "mention" => ["thread", "mention"], + "network" => ["thread", "network"], + "contact-id" => ["thread", "contact-id"], + ], + "query" => "FROM `thread` + STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`) + STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid` + LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid` + LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id` + LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id` + WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` + AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) + AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) + AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`)" + ], "owner-view" => [ "fields" => [ "id" => ["contact", "id"], From 11c3e4aefc7135d28900a9a0e9b35631573e1ac1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Aug 2020 16:56:53 +0000 Subject: [PATCH 5/5] Renamed condition arrays --- mod/network.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/mod/network.php b/mod/network.php index 6a7b8db5f7..d89ad6c4d3 100644 --- a/mod/network.php +++ b/mod/network.php @@ -499,24 +499,24 @@ function networkThreadedView(App $a, $update, $parent) $o .= status_editor($a, $x); } - $condition1 = ['uid' => local_user()]; - $condition2 = []; + $conditionFields = ['uid' => local_user()]; + $conditionStrings = []; if ($star) { - $condition1['starred'] = true; + $conditionFields['starred'] = true; } if ($conv) { - $condition1['mention'] = true; + $conditionFields['mention'] = true; } if ($nets) { - $condition1['network'] = $nets; + $conditionFields['network'] = $nets; } if ($datequery) { - $condition2 = DBA::mergeConditions($condition2, ["`received` <= ? ", DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())]); + $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` <= ? ", DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())]); } if ($datequery2) { - $condition2 = DBA::mergeConditions($condition2, ["`received` >= ? ", DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())]); + $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` >= ? ", DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())]); } if ($gid) { @@ -530,7 +530,7 @@ function networkThreadedView(App $a, $update, $parent) // NOTREACHED } - $condition2 = DBA::mergeConditions($condition2, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $gid]); + $conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $gid]); $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [ '$title' => DI::l10n()->t('Group: %s', $group['name']) @@ -538,7 +538,7 @@ function networkThreadedView(App $a, $update, $parent) } elseif ($cid) { $contact = Contact::getById($cid); if (DBA::isResult($contact)) { - $condition1['contact-id'] = $cid; + $conditionFields['contact-id'] = $cid; $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [ 'contacts' => [ModuleContact::getContactTemplateVars($contact)], @@ -575,22 +575,22 @@ function networkThreadedView(App $a, $update, $parent) switch ($order_mode) { case 'received': if ($last_received != '') { - $condition2 = DBA::mergeConditions($condition2, ["`received` < ?", $last_received]); + $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", $last_received]); } break; case 'commented': if ($last_commented != '') { - $condition2 = DBA::mergeConditions($condition2, ["`commented` < ?", $last_commented]); + $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", $last_commented]); } break; case 'created': if ($last_created != '') { - $condition2 = DBA::mergeConditions($condition2, ["`created` < ?", $last_created]); + $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", $last_created]); } break; case 'uriid': if ($last_uriid > 0) { - $condition2 = DBA::mergeConditions($condition2, ["`uri-id` < ?", $last_uriid]); + $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", $last_uriid]); } break; } @@ -599,14 +599,14 @@ function networkThreadedView(App $a, $update, $parent) if ($update) { if (!empty($parent)) { // Load only a single thread - $condition1['id'] = $parent; + $conditionFields['id'] = $parent; } elseif ($order === 'post') { // Only load new toplevel posts - $condition1['unseen'] = true; - $condition1['gravity'] = GRAVITY_PARENT; + $conditionFields['unseen'] = true; + $conditionFields['gravity'] = GRAVITY_PARENT; } else { // Load all unseen items - $condition1['unseen'] = true; + $conditionFields['unseen'] = true; } $params = ['order' => [$order_mode => true], 'limit' => 100]; @@ -615,7 +615,7 @@ function networkThreadedView(App $a, $update, $parent) $params = ['order' => [$order_mode => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; $table = 'network-thread-view'; } - $r = DBA::selectToArray($table, [], DBA::mergeConditions($condition1, $condition2), $params); + $r = DBA::selectToArray($table, [], DBA::mergeConditions($conditionFields, $conditionStrings), $params); return $o . network_display_post($a, $pager, (!$gid && !$cid && !$star), $update, $ordering, $r); }