From 14833edb2d44838ba4931d016fef273f6873b089 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 8 May 2018 22:00:32 +0000 Subject: [PATCH 1/3] Issue 4990: Fixes missing posts on network page --- include/conversation.php | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index ae12cf482..2a558cfca 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -900,38 +900,13 @@ function conversation_add_children($parents, $block_authors, $order) { $block_sql = $block_authors ? "AND NOT `author`.`hidden` AND NOT `author`.`blocked`" : ""; foreach ($parents AS $parent) { - $thread_items = dba::p(item_query()." AND `item`.`uid` = ? - AND `item`.`parent-uri` = ? $block_sql - ORDER BY `item`.`commented` DESC" . $limit, - local_user(), - $parent['uri'] - ); + $thread_items = dba::p(item_query()."AND `item`.`parent-uri` = ? + AND `item`.`uid` IN (0, ?) $block_sql + ORDER BY `parent` DESC, `gravity` ASC, `id` ASC" . $limit, + $parent['uri'], local_user()); + $comments = dba::inArray($thread_items); - // Check if the original item is in the result. - // When commenting from the community page there can be incomplete threads - if (count($comments) > 0) { - $parent_found = false; - foreach ($comments as $comment) { - if ($comment['uri'] == $comment['parent-uri']) { - $parent_found = true; - break; - } - } - if (!$parent_found) { - $comments = []; - } - } - - if (count($comments) == 0) { - $thread_items = dba::p(item_query()." AND `item`.`uid` = 0 - AND `item`.`parent-uri` = ? - ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1), - $parent['uri'] - ); - $comments = dba::inArray($thread_items); - } - if (count($comments) != 0) { $items = array_merge($items, $comments); } From 8d513d74bec17672f685f20e3792759fd7de5f6c Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 8 May 2018 22:08:25 +0000 Subject: [PATCH 2/3] Reverted SQL sorting --- include/conversation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/conversation.php b/include/conversation.php index 2a558cfca..4a9d799d2 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -902,7 +902,7 @@ function conversation_add_children($parents, $block_authors, $order) { foreach ($parents AS $parent) { $thread_items = dba::p(item_query()."AND `item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) $block_sql - ORDER BY `parent` DESC, `gravity` ASC, `id` ASC" . $limit, + ORDER BY `item`.`commented` DESC" . $limit, $parent['uri'], local_user()); $comments = dba::inArray($thread_items); From 6c792588fdb96b9cdd9053813cc759b481a55661 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 8 May 2018 22:26:49 +0000 Subject: [PATCH 3/3] Ensure to mostly fetch the item with an non zero user id --- include/conversation.php | 2 +- mod/display.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 4a9d799d2..5b7ebb78a 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -902,7 +902,7 @@ function conversation_add_children($parents, $block_authors, $order) { foreach ($parents AS $parent) { $thread_items = dba::p(item_query()."AND `item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) $block_sql - ORDER BY `item`.`commented` DESC" . $limit, + ORDER BY `item`.`uid` ASC, `item`.`commented` DESC" . $limit, $parent['uri'], local_user()); $comments = dba::inArray($thread_items); diff --git a/mod/display.php b/mod/display.php index eaf72c093..13a0ba465 100644 --- a/mod/display.php +++ b/mod/display.php @@ -344,10 +344,10 @@ function display_content(App $a, $update = false, $update_uid = 0) { } } - $r = dba::p(item_query()."AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = ?) - $sql_extra - ORDER BY `parent` DESC, `gravity` ASC, `id` ASC", - $item_id + $r = dba::p(item_query()."AND `item`.`parent-uri` = (SELECT `parent-uri` FROM `item` WHERE `id` = ?) + AND `item`.`uid` IN (0, ?) $sql_extra + ORDER BY `item`.`uid` ASC, `parent` DESC, `gravity` ASC, `id` ASC", + $item_id, local_user() ); if (!DBM::is_result($r)) {