Skip to content
Snippets Groups Projects
Commit e02e4640 authored by Andrzej Such's avatar Andrzej Such
Browse files

Postgrest: add comments to queries for diagnostic purposes

parent 55f55884
No related branches found
No related tags found
2 merge requests!827Merge develop changes to master,!782Postgrest: add comments to queries for diagnostic purposes
Showing
with 24 additions and 23 deletions
...@@ -30,7 +30,7 @@ BEGIN ...@@ -30,7 +30,7 @@ BEGIN
_limit = hivemind_postgrest_utilities.valid_number(_limit, 100, 1, 100, 'limit'); _limit = hivemind_postgrest_utilities.valid_number(_limit, 100, 1, 100, 'limit');
RETURN( RETURN(
SELECT jsonb_agg( SELECT jsonb_agg( -- bridge_api_account_notifications
jsonb_build_object( jsonb_build_object(
'id', hive_notification_cache.id, 'id', hive_notification_cache.id,
'type', hivemind_postgrest_utilities.get_notify_type_from_id(hive_notification_cache.type_id), 'type', hivemind_postgrest_utilities.get_notify_type_from_id(hive_notification_cache.type_id),
......
...@@ -26,7 +26,7 @@ BEGIN ...@@ -26,7 +26,7 @@ BEGIN
True); True);
RETURN ( RETURN (
SELECT to_jsonb(row) FROM ( SELECT to_jsonb(row) FROM ( -- bridge_api_get_community
SELECT SELECT
hc.id, hc.id,
hc.name, hc.name,
......
...@@ -28,7 +28,7 @@ BEGIN ...@@ -28,7 +28,7 @@ BEGIN
RETURN COALESCE( RETURN COALESCE(
( (
SELECT SELECT -- bridge_api_get_discussion
jsonb_object_agg((row.author || '/' || row.permlink), hivemind_postgrest_utilities.create_bridge_post_object(row, 0, NULL, row.is_pinned, True, row.replies)) jsonb_object_agg((row.author || '/' || row.permlink), hivemind_postgrest_utilities.create_bridge_post_object(row, 0, NULL, row.is_pinned, True, row.replies))
FROM ( FROM (
SELECT SELECT
......
...@@ -41,7 +41,7 @@ BEGIN ...@@ -41,7 +41,7 @@ BEGIN
IF _get_blacklists THEN IF _get_blacklists THEN
_result = ( _result = (
WITH np AS ( WITH np AS ( -- bridge_api_get_follow_list with _get_blacklists
SELECT SELECT
ha.name, ha.name,
hivemind_postgrest_utilities.extract_profile_metadata(ha.json_metadata, ha.posting_json_metadata)->'profile' AS profile hivemind_postgrest_utilities.extract_profile_metadata(ha.json_metadata, ha.posting_json_metadata)->'profile' AS profile
...@@ -63,7 +63,7 @@ BEGIN ...@@ -63,7 +63,7 @@ BEGIN
); );
ELSE ELSE
_result = ( _result = (
SELECT jsonb_agg ( SELECT jsonb_agg ( -- bridge_api_get_follow_list without _get_blacklists
jsonb_build_object( jsonb_build_object(
'name', row.name, 'name', row.name,
'blacklist_description', to_jsonb(''::TEXT), 'blacklist_description', to_jsonb(''::TEXT),
......
...@@ -18,7 +18,7 @@ BEGIN ...@@ -18,7 +18,7 @@ BEGIN
SELECT jsonb_agg(item) SELECT jsonb_agg(item)
INTO _result INTO _result
FROM ( FROM (
SELECT jsonb_build_array( SELECT jsonb_build_array( -- bridge_api_get_payout_stats
COALESCE(hc.name, '@' || hpv.author), COALESCE(hc.name, '@' || hpv.author),
COALESCE(hc.title, COALESCE('@' || hpv.author, 'Unknown')), COALESCE(hc.title, COALESCE('@' || hpv.author, 'Unknown')),
hpv.payout::float, hpv.payout::float,
......
...@@ -22,7 +22,7 @@ BEGIN ...@@ -22,7 +22,7 @@ BEGIN
_post_id = hivemind_postgrest_utilities.find_comment_id( _author, _permlink, True); _post_id = hivemind_postgrest_utilities.find_comment_id( _author, _permlink, True);
RETURN ( RETURN (
SELECT hivemind_postgrest_utilities.create_bridge_post_object(row, 0, NULL, False, True) FROM ( SELECT hivemind_postgrest_utilities.create_bridge_post_object(row, 0, NULL, False, True) FROM ( -- bridge_api_get_post
SELECT SELECT
hp.id, hp.id,
hp.author, hp.author,
......
...@@ -23,7 +23,7 @@ BEGIN ...@@ -23,7 +23,7 @@ BEGIN
'category', (CASE WHEN row.category IS NULL THEN '' ELSE row.category END), 'category', (CASE WHEN row.category IS NULL THEN '' ELSE row.category END),
'depth', row.depth 'depth', row.depth
) FROM ( ) FROM (
SELECT SELECT -- bridge_api_get_posts_header
ha_a.name as author, hpd_p.permlink as permlink, hcd.category as category, depth ha_a.name as author, hpd_p.permlink as permlink, hcd.category as category, depth
FROM FROM
hivemind_app.hive_posts hp hivemind_app.hive_posts hp
......
...@@ -20,7 +20,7 @@ BEGIN ...@@ -20,7 +20,7 @@ BEGIN
_observer := hivemind_postgrest_utilities.parse_string_argument_from_json(_params, _json_is_object, 'observer', 1, False); _observer := hivemind_postgrest_utilities.parse_string_argument_from_json(_params, _json_is_object, 'observer', 1, False);
PERFORM hivemind_postgrest_utilities.valid_account(_observer, True); PERFORM hivemind_postgrest_utilities.valid_account(_observer, True);
WITH main_communities AS ( WITH main_communities AS ( -- bridge_api_get_trending_topics
SELECT jsonb_build_array( SELECT jsonb_build_array(
community_data->>0, community_data->>0,
COALESCE(NULLIF(community_data->>1, ''), community_data->>0) COALESCE(NULLIF(community_data->>1, ''), community_data->>0)
......
...@@ -18,7 +18,7 @@ BEGIN ...@@ -18,7 +18,7 @@ BEGIN
True); True);
_result = ( _result = (
SELECT jsonb_agg( SELECT jsonb_agg( -- bridge_api_list_all_subscriptions
jsonb_build_array(row.name, row.title, row.role, row.role_title) jsonb_build_array(row.name, row.title, row.role, row.role_title)
) FROM ( ) FROM (
SELECT SELECT
......
...@@ -46,7 +46,7 @@ BEGIN ...@@ -46,7 +46,7 @@ BEGIN
END IF; END IF;
_result = ( _result = (
SELECT jsonb_agg( SELECT jsonb_agg( -- bridge_api_list_community_roles
jsonb_build_array(row.name, row.role, row.title) jsonb_build_array(row.name, row.role, row.title)
) FROM ( ) FROM (
SELECT SELECT
......
...@@ -30,7 +30,7 @@ BEGIN ...@@ -30,7 +30,7 @@ BEGIN
RETURN COALESCE( RETURN COALESCE(
( (
SELECT jsonb_agg(jsonb_build_array(row.name, row.role, row.title, row.created_at)) FROM ( SELECT jsonb_agg(jsonb_build_array(row.name, row.role, row.title, row.created_at)) FROM ( -- bridge_api_list_subscribers
SELECT SELECT
ha.name, ha.name,
hivemind_postgrest_utilities.get_role_name(COALESCE(hr.role_id,0)) AS role, hivemind_postgrest_utilities.get_role_name(COALESCE(hr.role_id,0)) AS role,
......
...@@ -36,7 +36,7 @@ BEGIN ...@@ -36,7 +36,7 @@ BEGIN
RETURN ( RETURN (
SELECT jsonb_agg(to_jsonb(row)) FROM SELECT jsonb_agg(to_jsonb(row)) FROM
( (
WITH notifications AS WITH notifications AS -- bridge_api_post_notifications
( (
SELECT SELECT
hnv.id, hnv.id,
......
...@@ -27,7 +27,7 @@ BEGIN ...@@ -27,7 +27,7 @@ BEGIN
SELECT ha.lastread_at INTO _last_read_at FROM hivemind_app.hive_accounts ha WHERE ha.id = _account_id; SELECT ha.lastread_at INTO _last_read_at FROM hivemind_app.hive_accounts ha WHERE ha.id = _account_id;
SELECT SELECT
COALESCE( COALESCE( -- bridge_api_unread_notifications
( (
SELECT hb.num SELECT hb.num
FROM hive.blocks_view hb -- very important for performance (originally it was a hivemind_app_blocks_view) FROM hive.blocks_view hb -- very important for performance (originally it was a hivemind_app_blocks_view)
......
...@@ -21,7 +21,7 @@ BEGIN ...@@ -21,7 +21,7 @@ BEGIN
IF _fat_node_style THEN IF _fat_node_style THEN
_result = ( _result = (
SELECT jsonb_agg ( SELECT jsonb_agg ( -- condenser_api_get_account_reputations with fat node style
to_jsonb(row) to_jsonb(row)
) FROM ( ) FROM (
SELECT ha.name AS account, ha.reputation AS reputation SELECT ha.name AS account, ha.reputation AS reputation
...@@ -33,7 +33,7 @@ BEGIN ...@@ -33,7 +33,7 @@ BEGIN
); );
ELSE ELSE
_result = jsonb_build_object('reputations', ( _result = jsonb_build_object('reputations', (
SELECT jsonb_agg ( SELECT jsonb_agg ( -- condenser_api_get_account_reputations without fat node style
to_jsonb(row) to_jsonb(row)
) FROM ( ) FROM (
SELECT ha.name AS name, ha.reputation AS reputation SELECT ha.name AS name, ha.reputation AS reputation
......
...@@ -59,7 +59,7 @@ BEGIN ...@@ -59,7 +59,7 @@ BEGIN
'reblogged_on', hivemind_postgrest_utilities.json_date(row.reblogged_at) 'reblogged_on', hivemind_postgrest_utilities.json_date(row.reblogged_at)
) )
) FROM ( ) FROM (
SELECT SELECT -- condenser_api_get_blog_entries
blog.entry_id::INT, blog.entry_id::INT,
ha.name as author, ha.name as author,
hpd.permlink, hpd.permlink,
...@@ -90,6 +90,7 @@ BEGIN ...@@ -90,6 +90,7 @@ BEGIN
); );
ELSE ELSE
_result = ( _result = (
-- condenser_api_get_blog
SELECT jsonb_agg( SELECT jsonb_agg(
jsonb_build_object( jsonb_build_object(
'blog', _account, 'blog', _account,
......
...@@ -23,7 +23,7 @@ BEGIN ...@@ -23,7 +23,7 @@ BEGIN
SELECT jsonb_agg ( SELECT jsonb_agg (
hivemind_postgrest_utilities.create_condenser_post_object(row, 0, _content_additions) hivemind_postgrest_utilities.create_condenser_post_object(row, 0, _content_additions)
) FROM ( ) FROM (
WITH replies AS WITH replies AS -- condenser_api_get_content with replies
( (
SELECT id SELECT id
FROM hivemind_app.live_posts_comments_view hp FROM hivemind_app.live_posts_comments_view hp
...@@ -81,7 +81,7 @@ BEGIN ...@@ -81,7 +81,7 @@ BEGIN
RETURN COALESCE(_result, '[]'::jsonb); RETURN COALESCE(_result, '[]'::jsonb);
ELSE ELSE
RETURN ( RETURN (
SELECT hivemind_postgrest_utilities.create_condenser_post_object(row, 0, _content_additions) FROM ( SELECT hivemind_postgrest_utilities.create_condenser_post_object(row, 0, _content_additions) FROM ( -- condenser_api_get_content without replies
SELECT SELECT
hp.id, hp.id,
hp.author, hp.author,
......
...@@ -46,7 +46,7 @@ BEGIN ...@@ -46,7 +46,7 @@ BEGIN
SELECT jsonb_agg ( SELECT jsonb_agg (
hivemind_postgrest_utilities.create_condenser_post_object(row, _truncate_body, False) hivemind_postgrest_utilities.create_condenser_post_object(row, _truncate_body, False)
) FROM ( ) FROM (
WITH blog_posts AS WITH blog_posts AS -- condenser_api_get_discussions_by_author_before_date
( (
SELECT SELECT
hp.id hp.id
......
...@@ -13,7 +13,7 @@ BEGIN ...@@ -13,7 +13,7 @@ BEGIN
_account = hivemind_postgrest_utilities.parse_string_argument_from_json(_params, _json_is_object, 'account', 0, True); _account = hivemind_postgrest_utilities.parse_string_argument_from_json(_params, _json_is_object, 'account', 0, True);
_account_id = hivemind_postgrest_utilities.find_account_id(hivemind_postgrest_utilities.valid_account(_account, False), True); _account_id = hivemind_postgrest_utilities.find_account_id(hivemind_postgrest_utilities.valid_account(_account, False), True);
RETURN ( RETURN (
SELECT to_jsonb(row) FROM ( SELECT to_jsonb(row) FROM ( -- condenser_api_get_follow_count
SELECT name AS account, ha.following AS following_count, ha.followers AS follower_count FROM hivemind_app.hive_accounts ha WHERE ha.id = _account_id SELECT name AS account, ha.following AS following_count, ha.followers AS follower_count FROM hivemind_app.hive_accounts ha WHERE ha.id = _account_id
) row ); ) row );
END; END;
......
...@@ -20,7 +20,7 @@ BEGIN ...@@ -20,7 +20,7 @@ BEGIN
RETURN COALESCE( RETURN COALESCE(
( (
SELECT jsonb_agg( SELECT jsonb_agg( -- condenser_api_get_followers
jsonb_build_object( jsonb_build_object(
'following', _params->'account', 'following', _params->'account',
'follower', row.name, 'follower', row.name,
......
...@@ -28,7 +28,7 @@ BEGIN ...@@ -28,7 +28,7 @@ BEGIN
) )
ORDER BY row.id DESC ORDER BY row.id DESC
) FROM ( ) FROM (
WITH following_set AS WITH following_set AS -- condenser_api_get_following
( (
SELECT SELECT
hf.id, hf.id,
......
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