Skip to content
Snippets Groups Projects
Commit 4faeaf8d authored by Mariusz Trela's avatar Mariusz Trela
Browse files

Introduced `condenser_get_account_reputations` SQL function

parent 6619ece6
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!347Refactoring + additional SQL functions
...@@ -590,7 +590,8 @@ def setup(db): ...@@ -590,7 +590,8 @@ def setup(db):
"condenser_get_names_by_followers.sql", "condenser_get_names_by_followers.sql",
"condenser_get_names_by_following.sql", "condenser_get_names_by_following.sql",
"condenser_get_names_by_reblogged.sql", "condenser_get_names_by_reblogged.sql",
"condenser_get_discussions_by_comments.sql" "condenser_get_discussions_by_comments.sql",
"condenser_get_account_reputations.sql"
] ]
from os.path import dirname, realpath from os.path import dirname, realpath
......
DROP FUNCTION IF EXISTS condenser_get_account_reputations;
CREATE OR REPLACE FUNCTION condenser_get_account_reputations(
in _account_lower_bound VARCHAR,
in _without_lower_bound BOOLEAN,
in _limit INTEGER
)
RETURNS TABLE
(
name hive_accounts.name%TYPE,
reputation hive_accounts.reputation%TYPE
)
AS
$function$
DECLARE
BEGIN
RETURN QUERY SELECT
ha.name, ha.reputation
FROM hive_accounts ha
WHERE _without_lower_bound OR ( ha.name >= _account_lower_bound )
ORDER BY name
LIMIT _limit;
END
$function$
language plpgsql STABLE;
...@@ -92,15 +92,8 @@ async def get_account_reputations(context, account_lower_bound: str = None, limi ...@@ -92,15 +92,8 @@ async def get_account_reputations(context, account_lower_bound: str = None, limi
async def _get_account_reputations_impl(db, fat_node_style, account_lower_bound, limit): async def _get_account_reputations_impl(db, fat_node_style, account_lower_bound, limit):
"""Enumerate account reputations.""" """Enumerate account reputations."""
limit = valid_limit(limit, 1000, None) limit = valid_limit(limit, 1000, None)
seek = ''
if account_lower_bound:
seek = "WHERE name >= :start"
sql = """SELECT name, reputation
FROM hive_accounts %s
ORDER BY name
LIMIT :limit""" % seek
sql = "SELECT * FROM condenser_get_account_reputations( '{}', {}, {} )".format( account_lower_bound, account_lower_bound is None, limit )
rows = await db.query_all(sql, start=account_lower_bound, limit=limit) rows = await db.query_all(sql, start=account_lower_bound, limit=limit)
if fat_node_style: if fat_node_style:
return [dict(account=r[0], reputation=r[1]) for r in rows] return [dict(account=r[0], reputation=r[1]) for r in rows]
......
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