From ab0c0e058aaa33c599f0b9c98dc6ad6cecfa60a2 Mon Sep 17 00:00:00 2001
From: Bartek Wrona <wrona@syncad.com>
Date: Wed, 11 Nov 2020 22:13:56 +0100
Subject: [PATCH] bridge_api.get_account_posts "by comment" optimization.

---
 .../bridge_get_account_posts_by_comments.sql          | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql
index 708730e43..bd02c7732 100644
--- a/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql
+++ b/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql
@@ -48,9 +48,14 @@ BEGIN
       hp.is_pinned,
       hp.curator_payout_value
   FROM
-      hive_posts_view hp
-  WHERE
-      hp.author_id = __account_id AND hp.depth > 0 AND ( __post_id = 0 OR hp.id < __post_id )
+  (
+    SELECT hp1.id
+    FROM hive_posts hp1 
+    WHERE hp1.author_id = __account_id AND hp1.counter_deleted = 0 AND hp1.depth > 0 AND ( __post_id = 0 OR hp1.id < __post_id )
+    ORDER BY hp1.id DESC
+    LIMIT _limit
+  ) ds
+  JOIN hive_posts_view hp ON ds.id = hp.id
   ORDER BY hp.id DESC
   LIMIT _limit;
 END
-- 
GitLab