From 57cb5637fc56bdc43c20ae0b6e0e8cf144d19ac4 Mon Sep 17 00:00:00 2001
From: Dessalines <dessalines@users.noreply.github.com>
Date: Mon, 7 Aug 2023 05:11:07 -0400
Subject: [PATCH] Fix ordering when doing a comment_parent type `list_comments`
 (#3823)

* Fix ordering when doing a comment_parent type GetPost.

* Fix missing options.
---
 crates/db_views/src/comment_view.rs | 4 ++--
 crates/db_views/src/post_view.rs    | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs
index 4cad1e74..45ab82bd 100644
--- a/crates/db_views/src/comment_view.rs
+++ b/crates/db_views/src/comment_view.rs
@@ -237,8 +237,8 @@ fn queries<'a>() -> Queries<
 
       query = query.filter(nlevel(comment::path).le(depth_limit));
 
-      // only order if filtering by a post id. DOS potential otherwise and max_depth + !post_id isn't used anyways (afaik)
-      if options.post_id.is_some() {
+      // only order if filtering by a post id, or parent_path. DOS potential otherwise and max_depth + !post_id isn't used anyways (afaik)
+      if options.post_id.is_some() || options.parent_path.is_some() {
         // Always order by the parent path first
         query = query.order_by(subpath(comment::path, 0, -1));
       }
diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs
index 30de18b6..0f844a49 100644
--- a/crates/db_views/src/post_view.rs
+++ b/crates/db_views/src/post_view.rs
@@ -308,7 +308,7 @@ fn queries<'a>() -> Queries<
       .unwrap_or(true)
     {
       // Do not hide read posts when it is a user profile view
-      if !is_profile_view {
+      if !options.is_profile_view {
         query = query.filter(post_read::post_id.is_null());
       }
     }
-- 
2.44.1