From 3afc7a749eb97d8a3d3da9b2eda8dcc89fb45d19 Mon Sep 17 00:00:00 2001
From: Dariusz Kedzierski <dkedzierski@syncad.com>
Date: Fri, 12 Jun 2020 20:10:57 +0200
Subject: [PATCH] Children count fix

---
 hive/indexer/posts.py     | 20 +++++++++++++-------
 hive/steem/http_client.py |  3 ++-
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/hive/indexer/posts.py b/hive/indexer/posts.py
index 0a219c53e..64da8b4e3 100644
--- a/hive/indexer/posts.py
+++ b/hive/indexer/posts.py
@@ -323,16 +323,22 @@ class Posts:
     @classmethod
     def update_child_count(cls, parent_id, op='+'):
         """ Increase/decrease child count by 1 """
+        sql = """SELECT children FROM hive_posts WHERE id = :id"""
+        children = int(DB.query(sql, id=parent_id))
+        if children == 32767:
+            children = 0
+
+        if op == '+':
+            children += 1
+        else:
+            children -= 1
+
         sql = """
             UPDATE 
                 hive_posts 
-            SET """
-        if op == '+':
-            sql += """children = (SELECT children FROM hive_posts WHERE id = :id) + 1"""
-        else:
-            sql += """children = (SELECT children FROM hive_posts WHERE id = :id) - 1"""
-        sql += """ WHERE id = :id"""
-        DB.query(sql, id=parent_id)
+            SET children = :children WHERE id = :id"""
+
+        DB.query(sql, id=parent_id, children=children)
 
     @classmethod
     def undelete(cls, op, date, pid):
diff --git a/hive/steem/http_client.py b/hive/steem/http_client.py
index 1233ec439..ed7fc6236 100644
--- a/hive/steem/http_client.py
+++ b/hive/steem/http_client.py
@@ -148,7 +148,8 @@ class HttpClient(object):
         body_data = json.dumps(body, ensure_ascii=False).encode('utf8')
 
         tries = 0
-        while tries < 100:
+        # changed number of tries to 25
+        while tries < 25:
             tries += 1
             secs = -1
             info = None
-- 
GitLab