From 72cbadedb281f42fa7a2dfbd3cf74937fc1bd54e Mon Sep 17 00:00:00 2001
From: ABW <andrzejl@syncad.com>
Date: Thu, 30 Jul 2020 20:28:00 +0200
Subject: [PATCH] [ABW]: [Fix] rshares removed from two more places - would
 break post initial sync hive_votes_accounts_permlinks_view used in one more
 place instead of hive_votes (most likely unused since query was totally
 broken)

---
 hive/indexer/posts.py           |  2 --
 hive/server/tags_api/methods.py | 27 ++++++++++++---------------
 scripts/update_hivemind_db.sql  |  5 ++---
 3 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/hive/indexer/posts.py b/hive/indexer/posts.py
index 07dcdfb99..b6820f0ec 100644
--- a/hive/indexer/posts.py
+++ b/hive/indexer/posts.py
@@ -342,7 +342,6 @@ class Posts:
                             max_accepted_payout = :max_accepted_payout,
                             author_rewards = :author_rewards,
                             children_abs_rshares = :children_abs_rshares,
-                            rshares = :net_rshares,
                             abs_rshares = :abs_rshares,
                             vote_rshares = :vote_rshares,
                             net_votes = :net_votes,
@@ -369,7 +368,6 @@ class Posts:
                          max_accepted_payout=legacy_amount(cpp['max_accepted_payout']),
                          author_rewards=cpp['author_rewards'],
                          children_abs_rshares=cpp['children_abs_rshares'],
-                         net_rshares=cpp['net_rshares'],
                          abs_rshares=cpp['abs_rshares'],
                          vote_rshares=cpp['vote_rshares'],
                          net_votes=cpp['net_votes'],
diff --git a/hive/server/tags_api/methods.py b/hive/server/tags_api/methods.py
index b564edb83..73eec2077 100644
--- a/hive/server/tags_api/methods.py
+++ b/hive/server/tags_api/methods.py
@@ -12,27 +12,24 @@ async def get_active_votes(context, author: str, permlink: str):
     db = context['db']
     sql = """
         SELECT 
-            ha_v.name as voter
-            ha_a.name as author
-            hpd.permlink as permlink
-            weight
-            rshares
-            vote_percent
-            last_update
-            num_changes
+            hv.voter,
+            hv.author,
+            hv.permlink,
+            hv.weight,
+            hv.rshares,
+            hv.percent,
+            hv.time,
+            hv.num_changes
         FROM
-            hive_votes hv
-        INNER JOIN hive_accounts ha_v ON ha_v.id = hv.voter_id
-        INNER JOIN hive_accounts ha_a ON ha_a.id = hv.author_id
-        INNER JOIN hive_permlink_data hpd ON hpd.id = hv.permlink_id
-        WHERE ha_a.name = :author AND hpd.permlink = :permlink
+            hive_votes_accounts_permlinks_view hv
+        WHERE hv.author = :author AND hv.permlink = :permlink
     """
     ret = []
     rows = await db.query_all(sql, author=author, permlink=permlink)
     for row in rows:
         ret.append(dict(voter=row.voter, author=row.author, permlink=row.permlink,
-                        weight=row.weight, rshares=row.rshares, vote_percent=row.vote_percent,
-                        last_update=str(row.last_update), num_changes=row.num_changes))
+                        weight=row.weight, rshares=row.rshares, vote_percent=row.percent,
+                        last_update=str(row.time), num_changes=row.num_changes))
     return ret
 
 @return_error_info
diff --git a/scripts/update_hivemind_db.sql b/scripts/update_hivemind_db.sql
index 0ca8ee12c..1dfde01ba 100644
--- a/scripts/update_hivemind_db.sql
+++ b/scripts/update_hivemind_db.sql
@@ -102,7 +102,6 @@ CREATE TABLE IF NOT EXISTS hive_posts_new (
   is_grayed BOOLEAN DEFAULT '0',
 
   -- important indexes
-  rshares BIGINT DEFAULT '-1',
   sc_trend NUMERIC(6) DEFAULT '0.0',
   sc_hot NUMERIC(6) DEFAULT '0.0',
 
@@ -210,12 +209,12 @@ FROM
 UPDATE hive_posts_new hpn SET (                             
   children, author_rep, flag_weight, total_votes, up_votes, payout,
   payout_at, updated_at, is_paidout, is_nsfw, is_declined, is_full_power,
-  is_hidden, is_grayed, rshares, sc_trend, sc_hot)
+  is_hidden, is_grayed, sc_trend, sc_hot)
 =
   (SELECT
     children, author_rep, flag_weight, total_votes, up_votes, payout,
     payout_at, updated_at, is_paidout, is_nsfw, is_declined, is_full_power,
-    is_hidden, is_grayed, rshares, sc_trend, sc_hot FROM hive_posts_cache hpc WHERE hpn.id = hpc.post_id);
+    is_hidden, is_grayed, sc_trend, sc_hot FROM hive_posts_cache hpc WHERE hpn.id = hpc.post_id);
 
 -- Populate table hive_post_data with bulk data from hive_posts_cache
 -- RAISE NOTICE 'Populate table hive_post_data with bulk data from hive_posts_cache';
-- 
GitLab