Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hive/hivemind
1 result
Show changes
Commits on Source (4)
......@@ -905,7 +905,7 @@ def setup(db):
LANGUAGE 'plpgsql'
AS
$function$
DECLARE
DECLARE
account_id INT;
BEGIN
SELECT INTO account_id COALESCE( ( SELECT id FROM hive_accounts WHERE name=_account ), 0 );
......@@ -1025,7 +1025,7 @@ def setup(db):
LANGUAGE 'plpgsql'
AS
$function$
DECLARE
DECLARE
post_id INT;
BEGIN
SELECT INTO post_id COALESCE( (SELECT hp.id
......@@ -1196,7 +1196,7 @@ def setup(db):
hp.allow_curation_rewards, hp.beneficiaries, hp.url, hp.root_title, hp.abs_rshares,
hp.active, hp.author_rewards
FROM hive_posts_view hp
INNER JOIN
INNER JOIN
(
SELECT hp2.id, hp2.root_id FROM hive_posts hp2
WHERE NOT hp2.is_muted
......@@ -1221,7 +1221,7 @@ def setup(db):
in _start_post_author hive_accounts.name%TYPE,
in _start_post_permlink hive_permlink_data.permlink%TYPE,
in _limit INT)
RETURNS SETOF database_api_post
RETURNS SETOF database_api_post
LANGUAGE sql
COST 100
STABLE
......@@ -1603,7 +1603,7 @@ def setup(db):
in _voter hive_accounts.name%TYPE, in _rshares hive_votes.rshares%TYPE)
RETURNS void
LANGUAGE sql
VOLATILE
VOLATILE
AS $BODY$
WITH __insert_info AS (
INSERT INTO hive_reputation_data
......@@ -1620,7 +1620,7 @@ def setup(db):
AND NOT hp.is_paidout --- voting on paidout posts shall have no effect
AND hv.reputation >= 0 --- voter's negative reputation eliminates vote from processing
AND (_rshares >= 0
AND (_rshares >= 0
OR (hv.reputation >= (ha.reputation - COALESCE((SELECT (hrd.rshares >> 6) -- if previous vote was a downvote we need to correct author reputation before current comparison to voter's reputation
FROM hive_reputation_data hrd
WHERE hrd.author_id = ha.id
......@@ -1631,7 +1631,7 @@ def setup(db):
ON CONFLICT ON CONSTRAINT hive_reputation_data_uk DO
UPDATE SET
rshares = EXCLUDED.rshares
RETURNING (xmax = 0) AS is_new_vote,
RETURNING (xmax = 0) AS is_new_vote,
(SELECT hrd.rshares
FROM hive_reputation_data hrd
--- Warning we want OLD row here, not both, so we're using old ID to select old one (new record has different value) !!!
......@@ -1685,6 +1685,106 @@ def setup(db):
"""
db.query_no_return(sql)
sql = """
DROP TYPE IF EXISTS bridge_api_post CASCADE;
CREATE TYPE bridge_api_post AS (
id INTEGER,
author VARCHAR,
parent_author VARCHAR,
author_rep FLOAT4,
root_title VARCHAR,
beneficiaries JSON,
max_accepted_payout VARCHAR,
percent_hbd INTEGER,
url TEXT,
permlink VARCHAR,
parent_permlink_or_category VARCHAR,
title VARCHAR,
body TEXT,
category VARCHAR,
depth SMALLINT,
promoted DECIMAL(10,3),
payout DECIMAL(10,3),
pending_payout DECIMAL(10,3),
payout_at TIMESTAMP,
is_paidout BOOLEAN,
children INTEGER,
votes INTEGER,
created_at TIMESTAMP,
updated_at TIMESTAMP,
rshares NUMERIC,
abs_rshares NUMERIC,
json TEXT,
is_hidden BOOLEAN,
is_grayed BOOLEAN,
total_votes BIGINT,
sc_trend FLOAT4,
role_title VARCHAR,
community_title VARCHAR,
role_id SMALLINT,
is_pinned BOOLEAN,
curator_payout_value VARCHAR
);
"""
db.query_no_return(sql)
sql = """
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_trends;
CREATE FUNCTION bridge_get_ranked_post_by_trends( in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
SELECT
hp.id,
hp.author,
hp.parent_author,
hp.author_rep,
hp.root_title,
hp.beneficiaries,
hp.max_accepted_payout,
hp.percent_hbd,
hp.url,
hp.permlink,
hp.parent_permlink_or_category,
hp.title,
hp.body,
hp.category,
hp.depth,
hp.promoted,
hp.payout,
hp.pending_payout,
hp.payout_at,
hp.is_paidout,
hp.children,
hp.votes,
hp.created_at,
hp.updated_at,
hp.rshares,
hp.abs_rshares,
hp.json,
hp.is_hidden,
hp.is_grayed,
hp.total_votes,
hp.sc_trend,
hp.role_title,
hp.community_title,
hp.role_id,
hp.is_pinned,
hp.curator_payout_value
FROM
(
SELECT
hp1.id
, hp1.sc_trend as trend
FROM hive_posts hp1 WHERE NOT hp1.is_paidout AND hp1.depth = 0 ORDER BY hp1.sc_trend DESC LIMIT _limit
) as trends
JOIN hive_posts_view hp ON hp.id = trends.id ORDER BY trends.trend DESC
$function$
language sql
"""
db.query_no_return(sql)
def reset_autovac(db):
"""Initializes/resets per-table autovacuum/autoanalyze params.
......@@ -1743,13 +1843,13 @@ def set_logged_table_attribute(db, logged):
db.query_no_return(sql.format(table, 'LOGGED' if logged else 'UNLOGGED'))
def execute_sql_script(query_executor, path_to_script):
""" Load and execute sql script from file
""" Load and execute sql script from file
Params:
query_executor - callable to execute query with
path_to_script - path to script
Returns:
depending on query_executor
Example:
print(execute_sql_script(db.query_row, "./test.sql"))
where test_sql: SELECT * FROM hive_state WHERE block_num = 0;
......@@ -1764,4 +1864,4 @@ def execute_sql_script(query_executor, path_to_script):
except Exception as ex:
log.exception("Error running sql script: {}".format(ex))
raise ex
return None
\ No newline at end of file
return None
......@@ -128,6 +128,18 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='',
db = context['db']
if sort == 'trending' and not ( start_author and start_permlink ) and ( not tag or tag == 'all' ):
sql = "SELECT * FROM bridge_get_ranked_post_by_trends( (:limit)::SMALLINT )"
posts = []
sql_result = await db.query_all(sql, limit=limit )
for row in sql_result:
post = _bridge_post_object(row)
post['active_votes'] = await find_votes_impl({'db':db}, row['author'], row['permlink'], VotesPresentation.BridgeApi)
post = await append_statistics_to_post(post, row, False, None)
posts.append(post)
return posts
sql = ''
pinned_sql = ''
......@@ -158,7 +170,7 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='',
if start_author and start_permlink:
if sort == 'trending':
sql = sql % """ AND hp.sc_trend <= (SELECT sc_trend FROM hive_posts WHERE author_id = (SELECT id FROM hive_accounts WHERE name = :author) AND permlink_id = (SELECT id FROM hive_permlink_data WHERE permlink = :permlink))
sql = sql % """ AND hp.sc_trend <= (SELECT sc_trend FROM hive_posts WHERE author_id = (SELECT id FROM hive_accounts WHERE name = :author) AND permlink_id = (SELECT id FROM hive_permlink_data WHERE permlink = :permlink))
AND hp.id != (SELECT id FROM hive_posts WHERE author_id = (SELECT id FROM hive_accounts WHERE name = :author) AND permlink_id = (SELECT id FROM hive_permlink_data WHERE permlink = :permlink)) %s """
elif sort == 'hot':
sql = sql % """ AND hp.sc_hot <= (SELECT sc_hot FROM hive_posts WHERE author_id = (SELECT id FROM hive_accounts WHERE name = :author) AND permlink_id = (SELECT id FROM hive_permlink_data WHERE permlink = :permlink))
......@@ -206,6 +218,7 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='',
pinned_post_ids = []
blacklists_for_user = None
if observer and context:
blacklists_for_user = await Mutes.get_blacklists_for_observer(observer, context)
......@@ -278,9 +291,9 @@ async def get_account_posts(context, sort, account, start_author='', start_perml
# pylint: disable=unused-variable
observer_id = await get_account_id(db, observer) if observer else None # TODO
sql = "---bridge_api.get_account_posts\n " + SQL_TEMPLATE + """ %s """
if sort == 'blog':
ids = await cursor.pids_by_blog(db, account, *start, limit)
posts = await load_posts(context['db'], ids)
......@@ -306,7 +319,7 @@ async def get_account_posts(context, sort, account, start_author='', start_perml
sql = sql % """ AND hp.id < (SELECT id FROM hive_posts WHERE author_id = (SELECT id FROM hive_accounts WHERE name = :author) AND permlink_id = (SELECT id FROM hive_permlink_data WHERE permlink = :permlink)) """
else:
sql = sql % """ """
posts = []
blacklists_for_user = None
if observer:
......@@ -328,7 +341,7 @@ async def get_relationship_between_accounts(context, account1, account2, observe
sql = """
SELECT state, blacklisted, follow_blacklists FROM hive_follows WHERE
follower = (SELECT id FROM hive_accounts WHERE name = :account1) AND
follower = (SELECT id FROM hive_accounts WHERE name = :account1) AND
following = (SELECT id FROM hive_accounts WHERE name = :account2)
"""
......@@ -347,11 +360,10 @@ async def get_relationship_between_accounts(context, account1, account2, observe
result['follows'] = True
elif state == 2:
result['ignores'] = True
if row['blacklisted']:
result['is_blacklisted'] = True
if row['follow_blacklists']:
result['follows_blacklists'] = True
return result
......@@ -433,39 +433,3 @@ async def pids_by_replies_to_account(db, start_author: str, start_permlink: str
""" % seek
return await db.query_col(sql, parent=parent_account, start_id=start_id, limit=limit)
async def get_accounts(db, accounts: list):
"""Returns accounts data for accounts given in list"""
ret = []
names = ["'{}'".format(a) for a in accounts]
sql = """SELECT *
FROM hive_accounts_info_view WHERE name IN ({})""".format(",".join(names))
result = await db.query_all(sql)
for row in result:
account_data = {}
if not row.raw_json is None and row.raw_json != '':
account_data = dict(loads(row.raw_json))
account_data['created_at'] = row.created_at.isoformat()
account_data['reputation'] = row.reputation
account_data['display_name'] = row.display_name
account_data['about'] = row.about
account_data['location'] = row.location
account_data['website'] = row.website
account_data['profile_image'] = row.profile_image
account_data['cover_image'] = row.cover_image
account_data['followers'] = row.followers
account_data['following'] = row.following
account_data['proxy'] = row.proxy
account_data['post_count'] = row.post_count
account_data['proxy_weight'] = row.proxy_weight
account_data['rank'] = row.rank
account_data['lastread_at'] = row.lastread_at.isoformat()
account_data['active_at'] = row.active_at.isoformat()
account_data['cached_at'] = row.cached_at.isoformat()
ret.append(account_data)
return ret
......@@ -577,14 +577,6 @@ async def _get_blog(db, account: str, start_index: int, limit: int = None):
return out
@return_error_info
async def get_accounts(context, accounts: list):
"""Returns accounts data for accounts given in list"""
assert accounts, "Empty parameters are not supported"
assert len(accounts) < 1000, "Query exceeds limit"
return await cursor.get_accounts(context['db'], accounts)
@return_error_info
async def get_active_votes(context, author: str, permlink: str):
""" Returns all votes for the given post. """
......
......@@ -90,7 +90,6 @@ def build_methods():
condenser_api.get_blog_entries,
condenser_api.get_account_reputations,
condenser_api.get_reblogged_by,
condenser_api.get_accounts,
condenser_api.get_active_votes
)})
......
......@@ -84,7 +84,6 @@ class HttpClient(object):
METHOD_API = dict(
lookup_accounts='condenser_api',
get_block='block_api',
get_accounts='condenser_api',
get_order_book='condenser_api',
get_feed_history='database_api',
get_dynamic_global_properties='database_api',
......
......@@ -419,7 +419,6 @@ class SteemStats(StatsAbstract):
'get_dynamic_global_properties': 20,
'get_block': 50,
'get_blocks_batch': 5,
'get_accounts': 3,
'get_content': 4,
'get_order_book': 20,
'get_feed_history': 20,
......