Skip to content
Snippets Groups Projects
Commit cdf49a0b authored by Andrzej Lisak's avatar Andrzej Lisak
Browse files

[ABW]: get_follow_count reimplemented as SQL function

parent 835eeedf
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!337reusing code of bridge calls in condenser_api
......@@ -1606,6 +1606,7 @@ def setup(db):
"condenser_get_content.sql",
"condenser_get_discussions_by_blog.sql",
"condenser_tags.sql",
"condenser_follows.sql",
"hot_and_trends.sql",
"update_hive_posts_children_count.sql"
]
......
DROP FUNCTION IF EXISTS condenser_get_follow_count;
CREATE FUNCTION condenser_get_follow_count( in _account VARCHAR,
out following hive_accounts.following%TYPE, out followers hive_accounts.followers%TYPE )
AS
$function$
DECLARE
__account_id INT;
BEGIN
__account_id = find_account_id( _account, True );
SELECT ha.following, ha.followers INTO following, followers FROM hive_accounts ha WHERE ha.id = __account_id;
-- following equals (SELECT COUNT(*) FROM hive_follows WHERE state = 1 AND following = __account_id)
-- followers equals (SELECT COUNT(*) FROM hive_follows WHERE state = 1 AND follower = __account_id)
END
$function$
language plpgsql STABLE;
......@@ -93,15 +93,6 @@ async def get_following(db, account: str, start: str, follow_type: str, limit: i
state=state, limit=limit)
async def get_follow_counts(db, account: str):
"""Return following/followers count for `account`."""
account_id = await _get_account_id(db, account)
sql = """SELECT following, followers
FROM hive_accounts
WHERE id = :account_id"""
return dict(await db.query_row(sql, account_id=account_id))
async def get_reblogged_by(db, author: str, permlink: str):
"""Return all rebloggers of a post."""
post_id = await _get_post_id(db, author, permlink)
......
......@@ -115,12 +115,13 @@ async def get_following(context, account: str, start: str, follow_type: str = No
@return_error_info
async def get_follow_count(context, account: str):
"""Get follow count stats. (EOL)"""
count = await cursor.get_follow_counts(
context['db'],
valid_account(account))
db = context['db']
account = valid_account(account)
sql = "SELECT * FROM condenser_get_follow_count( (:account)::VARCHAR )"
counters = await db.query_row(sql, account=account)
return dict(account=account,
following_count=count['following'],
follower_count=count['followers'])
following_count=counters[0],
follower_count=counters[1])
@return_error_info
async def get_reblogged_by(context, author: str, permlink: str):
......
Subproject commit fbc0c97245465eb46377a642b57ae1f9fce770ae
Subproject commit 143134910db644cb159e1f3e60f1d76e8eebc485
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment