Skip to content
Snippets Groups Projects

list_comments api call improvements

Merged Dariusz Kędzierski requested to merge dk-list-comments-by-fixes into develop
All threads resolved!
7 files
+ 202
68
Compare changes
  • Side-by-side
  • Inline
Files
7
  • 2e683c1f
    Added support for active flag · 2e683c1f
    Dariusz Kędzierski authored
    - Posting a comment and voting on post will now update active
      field in post
    - Added post object for database api post
    - Added a possibility to convert amount notation to nai notation
    - Other minor fixes
+ 35
7
@@ -118,12 +118,12 @@ def build_metadata():
@@ -118,12 +118,12 @@ def build_metadata():
sa.Column('abs_rshares', sa.BigInteger, nullable=False, server_default='0'),
sa.Column('abs_rshares', sa.BigInteger, nullable=False, server_default='0'),
sa.Column('vote_rshares', sa.BigInteger, nullable=False, server_default='0'),
sa.Column('vote_rshares', sa.BigInteger, nullable=False, server_default='0'),
sa.Column('net_votes', sa.Integer, nullable=False, server_default='0'),
sa.Column('net_votes', sa.Integer, nullable=False, server_default='0'),
sa.Column('active', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'),
sa.Column('active', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'), # TODO: the last time this post was "touched" by voting or reply
sa.Column('last_payout', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'),
sa.Column('last_payout', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'),
sa.Column('cashout_time', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'),
sa.Column('cashout_time', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'),
sa.Column('max_cashout_time', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'),
sa.Column('max_cashout_time', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'),
sa.Column('percent_hbd', sa.Integer, nullable=False, server_default='10000'),
sa.Column('percent_hbd', sa.Integer, nullable=False, server_default='10000'),
sa.Column('reward_weight', sa.Integer, nullable=False, server_default='0'),
sa.Column('reward_weight', sa.Integer, nullable=False, server_default='10000'), # Seems to be always 10000
sa.Column('parent_author_id', sa.Integer, nullable=False),
sa.Column('parent_author_id', sa.Integer, nullable=False),
sa.Column('parent_permlink_id', sa.BigInteger, nullable=False),
sa.Column('parent_permlink_id', sa.BigInteger, nullable=False),
@@ -447,12 +447,31 @@ def setup(db):
@@ -447,12 +447,31 @@ def setup(db):
ON CONFLICT DO NOTHING
ON CONFLICT DO NOTHING
;
;
if _parent_author != '' THEN
if _parent_author != '' THEN
 
-- update active flag
 
UPDATE
 
hive_posts hpm
 
SET
 
active = _date
 
WHERE
 
hpm.id = (
 
SELECT
 
hp.id
 
FROM
 
hive_posts hp
 
INNER JOIN hive_accounts ha ON ha.id = hp.author_id
 
INNER JOIN hive_permlink_data hpd ON hpd.id = hp.permlink_id
 
WHERE
 
ha.name = _parent_author AND
 
hpd.permlink = _parent_permlink
 
)
 
;
 
RETURN QUERY INSERT INTO hive_posts as hp
RETURN QUERY INSERT INTO hive_posts as hp
(parent_id, parent_author_id, parent_permlink_id, depth, community_id,
(parent_id, parent_author_id, parent_permlink_id, depth, community_id,
category_id,
category_id,
root_author_id, root_permlink_id,
root_author_id, root_permlink_id,
is_muted, is_valid,
is_muted, is_valid,
author_id, permlink_id, created_at, updated_at)
author_id, permlink_id, created_at, updated_at, active)
SELECT php.id AS parent_id, php.author_id as parent_author_id,
SELECT php.id AS parent_id, php.author_id as parent_author_id,
php.permlink_id as parent_permlink_id, php.depth + 1 as depth,
php.permlink_id as parent_permlink_id, php.depth + 1 as depth,
(CASE
(CASE
@@ -465,7 +484,8 @@ def setup(db):
@@ -465,7 +484,8 @@ def setup(db):
php.root_permlink_id as root_permlink_id,
php.root_permlink_id as root_permlink_id,
php.is_muted as is_muted, php.is_valid as is_valid,
php.is_muted as is_muted, php.is_valid as is_valid,
ha.id as author_id, hpd.id as permlink_id, _date as created_at,
ha.id as author_id, hpd.id as permlink_id, _date as created_at,
_date as updated_at
_date as updated_at,
 
_date as active
FROM hive_accounts ha,
FROM hive_accounts ha,
hive_permlink_data hpd,
hive_permlink_data hpd,
hive_posts php
hive_posts php
@@ -479,6 +499,7 @@ def setup(db):
@@ -479,6 +499,7 @@ def setup(db):
--- then also depth, is_valid and is_muted is impossible to change
--- then also depth, is_valid and is_muted is impossible to change
--- post edit part
--- post edit part
updated_at = _date,
updated_at = _date,
 
active = _date,
--- post undelete part (if was deleted)
--- post undelete part (if was deleted)
is_deleted = (CASE hp.is_deleted
is_deleted = (CASE hp.is_deleted
@@ -506,7 +527,7 @@ def setup(db):
@@ -506,7 +527,7 @@ def setup(db):
category_id,
category_id,
root_author_id, root_permlink_id,
root_author_id, root_permlink_id,
is_muted, is_valid,
is_muted, is_valid,
author_id, permlink_id, created_at, updated_at)
author_id, permlink_id, created_at, updated_at, active)
SELECT 0 AS parent_id, 0 as parent_author_id, 0 as parent_permlink_id, 0 as depth,
SELECT 0 AS parent_id, 0 as parent_author_id, 0 as parent_permlink_id, 0 as depth,
(CASE
(CASE
WHEN _date > _community_support_start_date THEN
WHEN _date > _community_support_start_date THEN
@@ -518,7 +539,8 @@ def setup(db):
@@ -518,7 +539,8 @@ def setup(db):
hpd.id as root_permlink_id, -- use perlink_id as root one if no parent
hpd.id as root_permlink_id, -- use perlink_id as root one if no parent
false as is_muted, true as is_valid,
false as is_muted, true as is_valid,
ha.id as author_id, hpd.id as permlink_id, _date as created_at,
ha.id as author_id, hpd.id as permlink_id, _date as created_at,
_date as updated_at
_date as updated_at,
 
_date as active
FROM hive_accounts ha,
FROM hive_accounts ha,
hive_permlink_data hpd
hive_permlink_data hpd
WHERE ha.name = _author and hpd.permlink = _permlink
WHERE ha.name = _author and hpd.permlink = _permlink
@@ -528,6 +550,7 @@ def setup(db):
@@ -528,6 +550,7 @@ def setup(db):
--- then also depth, is_valid and is_muted is impossible to change
--- then also depth, is_valid and is_muted is impossible to change
--- post edit part
--- post edit part
updated_at = _date,
updated_at = _date,
 
active = _date,
--- post undelete part (if was deleted)
--- post undelete part (if was deleted)
is_deleted = (CASE hp.is_deleted
is_deleted = (CASE hp.is_deleted
@@ -581,6 +604,8 @@ def setup(db):
@@ -581,6 +604,8 @@ def setup(db):
hp.community_id,
hp.community_id,
hp.parent_id,
hp.parent_id,
ha_a.name AS author,
ha_a.name AS author,
 
hp.active,
 
hp.author_rewards,
hp.author_id,
hp.author_id,
hpd_p.permlink,
hpd_p.permlink,
hpd.title,
hpd.title,
@@ -640,7 +665,10 @@ def setup(db):
@@ -640,7 +665,10 @@ def setup(db):
hr.title AS role_title,
hr.title AS role_title,
hr.role_id AS role_id,
hr.role_id AS role_id,
hc.title AS community_title,
hc.title AS community_title,
hc.name AS community_name
hc.name AS community_name,
 
hp.abs_rshares,
 
hp.max_cashout_time,
 
hp.reward_weight
FROM hive_posts hp
FROM hive_posts hp
JOIN hive_posts rp ON rp.author_id = hp.root_author_id AND rp.permlink_id = hp.root_permlink_id
JOIN hive_posts rp ON rp.author_id = hp.root_author_id AND rp.permlink_id = hp.root_permlink_id
JOIN hive_post_data rpd ON rp.id = rpd.id
JOIN hive_post_data rpd ON rp.id = rpd.id
Loading