From a24ae975a9a5f318f9f399d1d20c36ff91f99de8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 17 Oct 2020 07:31:03 +0000 Subject: [PATCH 1/4] Network: Fix continuous load issues --- src/Module/Conversation/Network.php | 30 +++++++++++------------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/Module/Conversation/Network.php b/src/Module/Conversation/Network.php index f21b3816a..34b0753a4 100644 --- a/src/Module/Conversation/Network.php +++ b/src/Module/Conversation/Network.php @@ -282,7 +282,7 @@ class Network extends BaseModule self::$forumContactId = $parameters['contact_id'] ?? 0; - self::$selectedTab = DI::pConfig()->get(local_user(), 'network.view', 'selected_tab', ''); + self::$selectedTab = ''; if (!empty($get['star'])) { self::$selectedTab = 'star'; @@ -296,11 +296,9 @@ class Network extends BaseModule self::$selectedTab = $get['order']; } - DI::pConfig()->set(local_user(), 'network.view', 'selected_tab', self::$selectedTab); - - self::$star = intval($get['star'] ?? 0); - self::$mention = intval($_GET['mention'] ?? 0); - self::$order = in_array(self::$selectedTab, ['received', 'commented', 'created', 'uriid']) ? self::$selectedTab : 'commented'; + self::$star = intval($get['star'] ?? 0); + self::$mention = intval($_GET['mention'] ?? 0); + self::$order = $get['order'] ?? 'commented'; self::$accountTypeString = $_GET['accounttype'] ?? $parameters['accounttype'] ?? ''; self::$accountType = User::getAccountTypeByString(self::$accountTypeString); @@ -321,7 +319,7 @@ class Network extends BaseModule self::$min_id = $_GET['min_id'] ?? null; self::$max_id = $_GET['max_id'] ?? null; - switch (self::$selectedTab) { + switch (self::$order) { case 'received': self::$max_id = $_GET['last_received'] ?? self::$max_id; break; @@ -420,26 +418,20 @@ class Network extends BaseModule $items = array_reverse($items); } - $parents_str = ''; if (DBA::isResult($items)) { - $parents_arr = []; - - foreach ($items as $item) { - if (!in_array($item['parent'], $parents_arr) && ($item['parent'] > 0)) { - $parents_arr[] = $item['parent']; - } - } - $parents_str = implode(', ', $parents_arr); + $parents = array_column($items, 'parent'); + } else { + $parents = []; } // We aren't going to try and figure out at the item, group, and page // level which items you've seen and which you haven't. If you're looking // at the top level network page just mark everything seen. - if (!self::$groupId && !self::$forumContactId && self::$selectedTab != 'star') { + if (!self::$groupId && !self::$forumContactId && !self::$star && !self::$mention) { $condition = ['unseen' => true, 'uid' => local_user()]; self::setItemsSeenByCondition($condition); - } elseif ($parents_str) { - $condition = ["`uid` = ? AND `unseen` AND `parent` IN (" . DBA::escape($parents_str) . ")", local_user()]; + } elseif (!empty($parents)) { + $condition = ['unseen' => true, 'uid' => local_user(), 'parent' => $parents]; self::setItemsSeenByCondition($condition); } From 14274bc2040d95242e01d55543a1bd2dd1a8ae62 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 17 Oct 2020 18:52:05 +0000 Subject: [PATCH 2/4] Store the selected network tab in a session variable --- src/Module/Conversation/Network.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Module/Conversation/Network.php b/src/Module/Conversation/Network.php index 34b0753a4..1138f254a 100644 --- a/src/Module/Conversation/Network.php +++ b/src/Module/Conversation/Network.php @@ -11,6 +11,7 @@ use Friendica\Content\Text\HTML; use Friendica\Core\ACL; use Friendica\Core\Hook; use Friendica\Core\Renderer; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -282,7 +283,7 @@ class Network extends BaseModule self::$forumContactId = $parameters['contact_id'] ?? 0; - self::$selectedTab = ''; + self::$selectedTab = Session::get('network-tab', ''); if (!empty($get['star'])) { self::$selectedTab = 'star'; @@ -296,9 +297,16 @@ class Network extends BaseModule self::$selectedTab = $get['order']; } + Session::set('network-tab', self::$selectedTab); + self::$star = intval($get['star'] ?? 0); self::$mention = intval($_GET['mention'] ?? 0); - self::$order = $get['order'] ?? 'commented'; + self::$order = $get['order'] ?? Session::get('network-order', 'commented'); + + self::$selectedTab = self::$selectedTab ?? self::$order; + + Session::set('network-tab', self::$selectedTab); + Session::set('network-order', self::$order); self::$accountTypeString = $_GET['accounttype'] ?? $parameters['accounttype'] ?? ''; self::$accountType = User::getAccountTypeByString(self::$accountTypeString); From 7db4fa6bf45cb1a7e6cc972bda96e1f1c434e1cf Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 17 Oct 2020 21:24:51 +0200 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Hypolite Petovan --- src/Module/Conversation/Network.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Module/Conversation/Network.php b/src/Module/Conversation/Network.php index 1138f254a..a1b23a1ac 100644 --- a/src/Module/Conversation/Network.php +++ b/src/Module/Conversation/Network.php @@ -300,7 +300,7 @@ class Network extends BaseModule Session::set('network-tab', self::$selectedTab); self::$star = intval($get['star'] ?? 0); - self::$mention = intval($_GET['mention'] ?? 0); + self::$mention = intval($get['mention'] ?? 0); self::$order = $get['order'] ?? Session::get('network-order', 'commented'); self::$selectedTab = self::$selectedTab ?? self::$order; @@ -308,7 +308,7 @@ class Network extends BaseModule Session::set('network-tab', self::$selectedTab); Session::set('network-order', self::$order); - self::$accountTypeString = $_GET['accounttype'] ?? $parameters['accounttype'] ?? ''; + self::$accountTypeString = $get['accounttype'] ?? $parameters['accounttype'] ?? ''; self::$accountType = User::getAccountTypeByString(self::$accountTypeString); self::$network = $get['nets'] ?? ''; @@ -324,12 +324,12 @@ class Network extends BaseModule DI::config()->get('system', 'itemspage_network')); } - self::$min_id = $_GET['min_id'] ?? null; - self::$max_id = $_GET['max_id'] ?? null; + self::$min_id = $get['min_id'] ?? null; + self::$max_id = $get['max_id'] ?? null; switch (self::$order) { case 'received': - self::$max_id = $_GET['last_received'] ?? self::$max_id; + self::$max_id = $get['last_received'] ?? self::$max_id; break; case 'commented': self::$max_id = $_GET['last_commented'] ?? self::$max_id; From 90b5421c017bf0476fa62dc138c448e3d517e11c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 18 Oct 2020 04:05:52 +0000 Subject: [PATCH 4/4] Use $get --- src/Module/Conversation/Network.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Module/Conversation/Network.php b/src/Module/Conversation/Network.php index a1b23a1ac..abe836f27 100644 --- a/src/Module/Conversation/Network.php +++ b/src/Module/Conversation/Network.php @@ -332,13 +332,13 @@ class Network extends BaseModule self::$max_id = $get['last_received'] ?? self::$max_id; break; case 'commented': - self::$max_id = $_GET['last_commented'] ?? self::$max_id; + self::$max_id = $get['last_commented'] ?? self::$max_id; break; case 'created': - self::$max_id = $_GET['last_created'] ?? self::$max_id; + self::$max_id = $get['last_created'] ?? self::$max_id; break; case 'uriid': - self::$max_id = $_GET['last_uriid'] ?? self::$max_id; + self::$max_id = $get['last_uriid'] ?? self::$max_id; break; } }