From 73248aadd5a3d862002d3afcd2cecd4ea8436fa3 Mon Sep 17 00:00:00 2001
From: Mario Vavti <mario@mariovavti.com>
Date: Sat, 27 Apr 2019 15:35:41 +0200
Subject: possible sql performance improvement

---
 include/items.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/items.php b/include/items.php
index c08deb3a0..95b696034 100755
--- a/include/items.php
+++ b/include/items.php
@@ -4278,7 +4278,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
 	if($arr['mid'])
 		$sql_options .= " and parent_mid = '" . dbesc($arr['mid']) . "' ";
 
-	$sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE item_thread_top = 1 $sql_options $item_normal ) ";
+	$sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE $item_uids and item_thread_top = 1 $sql_options $item_normal ) ";
 
 	if($arr['since_id'])
 		$sql_extra .= " and item.id > " . $since_id . " ";
-- 
cgit v1.2.3


From 405e07f0a232445e179e2df821e77007f3b6d33d Mon Sep 17 00:00:00 2001
From: Mario Vavti <mario@mariovavti.com>
Date: Sat, 27 Apr 2019 23:01:05 +0200
Subject: improve channel date query

---
 Zotlabs/Module/Channel.php | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php
index d4ef94e06..144c2472a 100644
--- a/Zotlabs/Module/Channel.php
+++ b/Zotlabs/Module/Channel.php
@@ -46,14 +46,14 @@ class Channel extends Controller {
 		$channel = App::get_channel();
 
 		if((local_channel()) && (argc() > 2) && (argv(2) === 'view')) {
-            $which = $channel['channel_address'];
-            $profile = argv(1);
-        }
+			$which = $channel['channel_address'];
+			$profile = argv(1);
+		}
 
 		$channel = channelx_by_nick($which);
-        if(! $channel) {
-            http_status_exit(404, 'Not found');
-        }
+		if(! $channel) {
+			http_status_exit(404, 'Not found');
+		}
 
 		// handle zot6 channel discovery 
 
@@ -310,10 +310,6 @@ class Channel extends Controller {
 				$sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
 			}
 
-			if($datequery || $datequery2) {
-				$sql_extra2 .= " and item.item_thread_top != 0 ";
-			}
-
 			if($order === 'post')
 				$ordering = "created";
 			else
@@ -342,7 +338,7 @@ class Channel extends Controller {
 						AND (abook.abook_blocked = 0 or abook.abook_flags is null)
 						AND item.item_wall = 1 AND item.item_thread_top = 1
 						$sql_extra $sql_extra2 
-						ORDER BY $ordering DESC $pager_sql ",
+						ORDER BY $ordering DESC, item_id $pager_sql ",
 						intval(App::$profile['profile_uid'])
 					);
 				}
-- 
cgit v1.2.3