Skip to content
Snippets Groups Projects
Commit 51ccee3b authored by Mariusz Trela's avatar Mariusz Trela Committed by Mariusz Trela
Browse files

The call `list_votes` sorted by `comment_voter` works

parent 5f7432f9
No related branches found
No related tags found
4 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!138Small typos fixed,!129The calls 'list_votes'/'find_votes' work
This commit is part of merge request !129. Comments created here will be created in the context of that merge request.
......@@ -872,14 +872,15 @@ def setup(db):
db.query_no_return(sql)
sql = """
DROP VIEW IF EXISTS list_votes_by_voter_comment;
DROP VIEW IF EXISTS list_votes( character varying, character varying, character varying, int, bool );
CREATE OR REPLACE FUNCTION public.list_votes_by_voter_comment
CREATE OR REPLACE FUNCTION public.list_votes
(
in _VOTER hive_accounts.name%TYPE,
in _AUTHOR hive_accounts.name%TYPE,
in _PERMLINK hive_permlink_data.permlink%TYPE,
in _LIMIT INT
in _LIMIT INT,
in _IS_VOTER_COMMENT_SORT BOOLEAN
)
RETURNS TABLE
(
......@@ -912,29 +913,55 @@ def setup(db):
_PERMLINK_ID = find_comment_id( _AUTHOR, _PERMLINK, True);
RETURN QUERY
(
SELECT
v.voter,
v.author,
v.permlink,
v.weight,
v.rshares,
v.percent,
v.time,
v.num_changes,
v.reputation
FROM
hive_votes_accounts_permlinks_view v
WHERE
( v.voter_id = _VOTER_ID and v.permlink_id >= _PERMLINK_ID )
OR
( v.voter_id > _VOTER_ID )
ORDER BY
voter_id,
permlink_id
LIMIT _LIMIT
);
IF _IS_VOTER_COMMENT_SORT = True THEN
RETURN QUERY
(
SELECT
v.voter,
v.author,
v.permlink,
v.weight,
v.rshares,
v.percent,
v.time,
v.num_changes,
v.reputation
FROM
hive_votes_accounts_permlinks_view v
WHERE
( v.voter_id = _VOTER_ID and v.permlink_id >= _PERMLINK_ID )
OR
( v.voter_id > _VOTER_ID )
ORDER BY
voter_id,
permlink_id
LIMIT _LIMIT
);
ELSE
RETURN QUERY
(
SELECT
v.voter,
v.author,
v.permlink,
v.weight,
v.rshares,
v.percent,
v.time,
v.num_changes,
v.reputation
FROM
hive_votes_accounts_permlinks_view v
WHERE
( v.permlink_id = _PERMLINK_ID and v.voter_id >= _VOTER_ID )
OR
( v.permlink_id > _PERMLINK_ID )
ORDER BY
permlink_id,
voter_id
LIMIT _LIMIT
);
END IF;
END
$BODY$;
......
......@@ -224,24 +224,12 @@ async def list_votes(context, start: list, limit: int, order: str, votes_present
assert len(start) == 3, "Expecting 3 elements in start array"
db = context['db']
sql = ""
if order == "by_comment_voter":
sql += """
WHERE
author >= :author AND
permlink >= :permlink AND
voter >= :voter
ORDER BY
post_id ASC,
voter_id ASC
LIMIT
:limit
"""
rows = await db.query_all(sql, author=start[0], permlink=start[1], voter=start[2], limit=limit)
sql=""
if order == "by_voter_comment":
sql = "select * from list_votes_by_voter_comment( '{}', '{}', '{}', {} )".format( start[0], start[1], start[2], limit )
sql = "select * from list_votes( '{}', '{}', '{}', {}, true )".format( start[0], start[1], start[2], limit )
else:
sql = "select * from list_votes( '{}', '{}', '{}', {}, false )".format( start[2], start[0], start[1], limit )
rows = await db.query_all(sql)
......
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