Skip to content

Commit

Permalink
Postgrest - refactor hivemind_endpoints.database_api_find_votes
Browse files Browse the repository at this point in the history
  • Loading branch information
asuch committed Nov 21, 2024
1 parent 0a9ce2c commit 383cbe2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 87 deletions.
1 change: 0 additions & 1 deletion hive/db/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,6 @@ def setup_runtime_code(db):
"postgrest/utilities/create_condenser_post_object.sql",
"postgrest/condenser_api/condenser_api_get_blog.sql",
"postgrest/condenser_api/condenser_api_get_content.sql",
"postgrest/utilities/vote_arguments.sql",
"postgrest/database_api/database_api_find_votes.sql",
"postgrest/database_api/database_api_list_votes.sql",
"postgrest/condenser_api/condenser_api_get_active_votes.sql",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,24 @@ STABLE
AS
$$
DECLARE
_vote_args hivemind_postgrest_utilities.vote_arguments;
_result JSONB;
_post_id INT;
BEGIN
_vote_args := hivemind_postgrest_utilities.get_validated_vote_arguments(_params, _json_is_object);
PERFORM hivemind_postgrest_utilities.validate_json_parameters(_json_is_object, _params, '{"author","permlink"}', '{"string","string"}');

SELECT jsonb_build_object(
'votes', COALESCE(jsonb_agg(
jsonb_build_object(
'id', votes.id,
'voter', votes.voter,
'author', votes.author,
'weight', votes.weight,
'vote_percent', votes.percent,
'rshares', votes.rshares,
'permlink', votes.permlink,
'last_update', votes.last_update,
'num_changes', votes.num_changes
)), '[]'::jsonb)
) AS _result INTO _result
_post_id =
hivemind_postgrest_utilities.find_comment_id(
hivemind_postgrest_utilities.valid_account(
hivemind_postgrest_utilities.parse_string_argument_from_json(_params, _json_is_object, 'author', 0, True),
False),
hivemind_postgrest_utilities.valid_permlink(
hivemind_postgrest_utilities.parse_string_argument_from_json(_params, _json_is_object, 'permlink', 1, True),
False),
True);

FROM (SELECT * FROM hivemind_app.find_votes(_vote_args.author, _vote_args.permlink, 1000)) AS votes;

RETURN _result;
RETURN jsonb_build_object(
'votes',
hivemind_postgrest_utilities.list_votes(_post_id, 1000, 'get_votes_for_posts'::hivemind_postgrest_utilities.list_votes_case, 'database_api'::hivemind_postgrest_utilities.vote_presentation)
);
END;
$$
;
25 changes: 0 additions & 25 deletions hive/db/sql_scripts/postgrest/utilities/vote_arguments.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ test_name: Hivemind
marks:
- patterntest
- negative
- postgrest_ignore

includes:
- !include ../../common.yaml
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 383cbe2

Please sign in to comment.