From 3b95db26503636896952fa08042dab0ad20d75f1 Mon Sep 17 00:00:00 2001 From: asuch <asuch@syncad.com> Date: Wed, 15 Jan 2025 11:06:44 +0100 Subject: [PATCH] Remove postgrest code for condenser - get_state. It is not finished and this function is not needed --- hive/db/schema.py | 2 - .../condenser_api/condenser_api_get_state.sql | 46 -------- .../postgrest/utilities/get_api_method.sql | 2 +- .../postgrest/utilities/get_state_tools.sql | 107 ------------------ 4 files changed, 1 insertion(+), 156 deletions(-) delete mode 100644 hive/db/sql_scripts/postgrest/condenser_api/condenser_api_get_state.sql delete mode 100644 hive/db/sql_scripts/postgrest/utilities/get_state_tools.sql diff --git a/hive/db/schema.py b/hive/db/schema.py index 7ac518a35..69a4fa9d3 100644 --- a/hive/db/schema.py +++ b/hive/db/schema.py @@ -594,8 +594,6 @@ def setup_runtime_code(db): "postgrest/utilities/valid_tag.sql", "postgrest/utilities/find_category_id.sql", "postgrest/condenser_api/condenser_api_get_trending_tags.sql", - "postgrest/utilities/get_state_tools.sql", - "postgrest/condenser_api/condenser_api_get_state.sql", "postgrest/condenser_api/condenser_api_get_account_reputations.sql", "postgrest/utilities/check_community.sql", "postgrest/utilities/valid_community.sql", diff --git a/hive/db/sql_scripts/postgrest/condenser_api/condenser_api_get_state.sql b/hive/db/sql_scripts/postgrest/condenser_api/condenser_api_get_state.sql deleted file mode 100644 index 6a0762fb1..000000000 --- a/hive/db/sql_scripts/postgrest/condenser_api/condenser_api_get_state.sql +++ /dev/null @@ -1,46 +0,0 @@ -DROP FUNCTION IF EXISTS hivemind_endpoints.condenser_api_get_state; -CREATE FUNCTION hivemind_endpoints.condenser_api_get_state(IN _params JSONB) -RETURNS JSONB -LANGUAGE 'plpgsql' -STABLE -AS -$$ -DECLARE -_path TEXT; -_parts TEXT[]; -_state JSONB; -_ACCOUNT_TAB_KEYS TEXT[] DEFAULT '{blog, feed, comments, recent-replies}'; - -_field_text_1 TEXT; - -BEGIN - RAISE EXCEPTION '%', hivemind_postgrest_utilities.raise_parameter_validation_exception('condenser_api get state is not supported'); - _params = hivemind_postgrest_utilities.validate_json_arguments(_params, '{"path"}', '{"string"}'); - _path = hivemind_postgrest_utilities.parse_argument_from_json(_params, 'path', 0, False); - SELECT path, parts FROM hivemind_postgrest_utilities.gs_normalize_path(_path) AS (path TEXT, parts TEXT[]) INTO _path, _parts; - - -- account (feed, blog, comments, replies) - IF _parts[1] IS NOT NULL AND position('@' IN _parts[1]) <> 0 THEN - IF _parts[2] = 'transfers' THEN - RAISE EXCEPTION '%', hivemind_postgrest_utilities.raise_parameter_validation_exception('transfers API not served here'); - END IF; - IF _parts[3] IS NOT NULL THEN - RAISE EXCEPTION '%', hivemind_postgrest_utilities.raise_parameter_validation_exception('unexpected account path[2] ' || _path); - END IF; - IF _parts[2] = '' THEN - _parts[2] = 'blog'; - END IF; - -- _field_text_1 - account - _field_text_1 = hivemind_postgrest_utilities.valid_account(substring(_parts[1] FROM 2)); - -- in python get state, there is a call _load_account, which calls some others functions and calls something like that. Calling directly that method - _state = jsonb_set(_state, '{accounts}', hivemind_postgrest_utilities.gs_get_hive_account_info_view_query_string(_field_text_1)); - IF _parts[2] = ANY(_ACCOUNT_TAB_KEYS) THEN - - END IF; - END IF; -END; -$$ -; - - --@steemit - --category/@steemit/firstpost \ No newline at end of file diff --git a/hive/db/sql_scripts/postgrest/utilities/get_api_method.sql b/hive/db/sql_scripts/postgrest/utilities/get_api_method.sql index b9d53e6a6..c621472af 100644 --- a/hive/db/sql_scripts/postgrest/utilities/get_api_method.sql +++ b/hive/db/sql_scripts/postgrest/utilities/get_api_method.sql @@ -16,7 +16,7 @@ BEGIN WHEN __method_type = 'get_trending_tags' THEN result := hivemind_endpoints.condenser_api_get_trending_tags(__params); WHEN __method_type = 'get_state' THEN - result := hivemind_endpoints.condenser_api_get_state(__params); + RAISE EXCEPTION '%', hivemind_postgrest_utilities.raise_parameter_validation_exception('condenser_api get state is not supported'); WHEN __method_type = 'get_account_reputations' THEN result := hivemind_endpoints.condenser_api_get_account_reputations(__params, /* _fat_node_style */ True); WHEN __method_type = 'get_blog' THEN diff --git a/hive/db/sql_scripts/postgrest/utilities/get_state_tools.sql b/hive/db/sql_scripts/postgrest/utilities/get_state_tools.sql deleted file mode 100644 index 7a94076f1..000000000 --- a/hive/db/sql_scripts/postgrest/utilities/get_state_tools.sql +++ /dev/null @@ -1,107 +0,0 @@ --- methods which are used only for condenser_api - get state - -DROP FUNCTION IF EXISTS hivemind_postgrest_utilities.gs_normalize_path; -CREATE FUNCTION hivemind_postgrest_utilities.gs_normalize_path(in _path TEXT) -RETURNS RECORD -LANGUAGE plpgsql -IMMUTABLE -AS -$BODY$ -DECLARE - _char_position INT; - _parts TEXT[]; - _modified_path TEXT; - _normalized_path RECORD; -BEGIN - IF left(_path, 1) = '/' THEN - _path = substring(_path from 2); - END IF; - - _char_position = position('?' in _path); - IF _char_position <> 0 THEN - _path = substring(_path FROM 1 FOR _char_position); - END IF; - - IF _path = '' THEN - _path = 'trending'; - END IF; - - IF position('#' IN _path) <> 0 THEN - RAISE EXCEPTION '%', hivemind_postgrest_utilities.raise_parameter_validation_exception('path contains hash mark (#)'); - END IF; - - _modified_path = _path; - - LOOP - _char_position = position('/' IN _modified_path); - IF _char_position <> 0 THEN - _parts = array_append(_parts, substring(_modified_path FROM 1 FOR _char_position - 1)); - _modified_path = substring(_modified_path FROM _char_position + 1); - ELSE - _parts = array_append(_parts, substring(_modified_path FROM 1)); - EXIT; - - END IF; - END LOOP; - - IF CARDINALITY(_parts) = 4 AND _parts[4] = '' THEN - _parts = array_remove(_parts, _parts[4]); - END IF; - - IF CARDINALITY(_parts) > 3 THEN - RAISE EXCEPTION '%', hivemind_postgrest_utilities.raise_parameter_validation_exception('too many parts in path:' || _path); - END IF; - - LOOP - IF CARDINALITY(_parts) < 3 THEN - - _parts = array_append(_parts, NULL); - ELSE - EXIT; - END IF; - END LOOP; - - SELECT _path, _parts INTO _normalized_path; - RETURN _normalized_path; -END; -$BODY$ -; - -DROP FUNCTION IF EXISTS hivemind_postgrest_utilities.gs_get_hive_account_info_view_query_string; -CREATE FUNCTION hivemind_postgrest_utilities.gs_get_hive_account_info_view_query_string(IN _name TEXT) -RETURNS JSONB -LANGUAGE plpgsql -STABLE -AS -$BODY$ -DECLARE -_result JSONB DEFAULT '{"' || _name || '":""}'; -BEGIN -_result = jsonb_set(_result, ('{' || _name || '}')::text[], ( - SELECT to_jsonb(row) FROM ( - SELECT - ha.id, - ha.name, - ha.post_count, - ha.created_at, - ha.active_at, - ha.reputation, - ha.rank, - ha.following, - ha.followers, - ha.lastread_at, - ha.posting_json_metadata, - ha.json_metadata - FROM hivemind_app.hive_accounts_info_view ha - WHERE ha.name = _name - ) row) -); - -IF _result->>_name IS NULL THEN - RAISE EXCEPTION '%', hivemind_postgrest_utilities.invalid_account_exception('account not found: ' || _name); -ELSE - RETURN _result; -END IF; -END; -$BODY$ -; \ No newline at end of file -- GitLab