Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
d87e6ba0
Commit
d87e6ba0
authored
2 months ago
by
Dan Notestein
Browse files
Options
Downloads
Patches
Plain Diff
temporarily try to match tests
parent
a8a9e4d7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!827
Merge develop changes to master
,
!814
speed up json checking
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hive/db/sql_scripts/postgrest/home.sql
+36
-18
36 additions, 18 deletions
hive/db/sql_scripts/postgrest/home.sql
hive/db/sql_scripts/postgrest/utilities/check_general_json_format.sql
+0
-43
0 additions, 43 deletions
...scripts/postgrest/utilities/check_general_json_format.sql
with
36 additions
and
61 deletions
hive/db/sql_scripts/postgrest/home.sql
+
36
−
18
View file @
d87e6ba0
...
...
@@ -7,40 +7,58 @@ AS
$$
DECLARE
__request_data
JSON
=
$
1
;
__id
JSONB
;
__id
TEXT
;
__jsonrpc
TEXT
;
__method
TEXT
;
__params
JSON
;
__api_type
TEXT
;
__method_type
TEXT
;
__params_jsonb
JSONB
;
__request_params
JSONB
;
BEGIN
__id
=
__request_data
->
'id'
;
__jsonrpc
=
__request_data
->>
'jsonrpc'
;
IF
__jsonrpc
!=
'2.0'
OR
__jsonrpc
IS
NULL
THEN
RAISE
EXCEPTION
'%'
,
hivemind_postgrest_utilities
.
raise_invalid_json_format_exception
(
'Invalid JSON-RPC'
);
END
IF
;
__id
=
__request_data
->>
'id'
;
IF
__id
IS
NULL
THEN
return
jsonb_build_object
(
'jsonrpc'
,
'2.0'
,
'error'
,
'id required'
);
END
IF
;
__method
=
__request_data
->>
'method'
;
if
__method
is
NULL
THEN
RETURN
jsonb_build_object
(
'jsonrpc'
,
'2.0'
,
'error'
,
'no method passed'
,
'id'
,
__id
);
END
IF
;
--early check to reject methods that require parameters
__params
=
__request_data
->
'params'
;
IF
__method
NOT
IN
(
'hive.db_head_state'
,
'condenser.get_trending_tags'
,
IF
__method
NOT
IN
(
'call'
,
'hive.db_head_state'
,
'condenser.get_trending_tags'
,
'bridge.list_pop_communities'
,
'bridge.get_payout_stats'
,
'bridge.get_trending_topics'
,
'bridge.list_muted_reasons_enum'
)
THEN
IF
__params
is
NULL
THEN
RETURN
jsonb_build_object
(
'jsonrpc'
,
'2.0'
,
'error'
,
'
no
parameters
passed
'
,
'id'
,
__id
);
RETURN
jsonb_build_object
(
'jsonrpc'
,
'2.0'
,
'error'
,
'
this method requires
parameters'
,
'id'
,
__id
);
END
IF
;
END
IF
;
--handle 'call' method (probably should remove this if condition, no one uses and it is inefficiently implemented)
if
lower
(
__method
)
=
'call'
THEN
if
jsonb_array_length
(
__params
)
<
2
THEN
RAISE
EXCEPTION
'%'
,
hivemind_postgrest_utilities
.
raise_invalid_json_format_exception
(
'Invalid JSON-RPC'
);
END
IF
;
__api_type
=
__params
->>
0
;
__method_type
=
__params
->>
1
;
-- this 'call' keyword in test cases gives another error messages, so it is important
__params
=
jsonb_build_object
(
'used_call_keyword'
,
True
,
'params'
,
__params
->
2
);
ELSE
SELECT
split_part
(
__method
,
'.'
,
1
)
INTO
__api_type
;
SELECT
split_part
(
__method
,
'.'
,
2
)
INTO
__method_type
;
END
IF
;
__params_jsonb
=
__params
::
JSONB
;
__request_params
=
hivemind_postgrest_utilities
.
check_general_json_format
(
__request_data
->>
'jsonrpc'
,
__method
,
__params_jsonb
,
__id
);
RETURN
jsonb_build_object
(
'jsonrpc'
,
'2.0'
,
'id'
,
__id
,
'result'
,
hivemind_postgrest_utilities
.
dispatch
(
__request_params
->>
'api_type'
,
__request_params
->>
'method_type'
,
__params_jsonb
)
);
RETURN
jsonb_build_object
(
'jsonrpc'
,
'2.0'
,
'id'
,
__id
,
'result'
,
hivemind_postgrest_utilities
.
dispatch
(
__api_type
,
__method_type
,
__params_jsonb
)
);
EXCEPTION
WHEN
raise_exception
THEN
...
...
This diff is collapsed.
Click to expand it.
hive/db/sql_scripts/postgrest/utilities/check_general_json_format.sql
+
0
−
43
View file @
d87e6ba0
DROP
FUNCTION
IF
EXISTS
hivemind_postgrest_utilities
.
check_general_json_format
;
CREATE
FUNCTION
hivemind_postgrest_utilities
.
check_general_json_format
(
IN
__jsonrpc
TEXT
,
IN
__method
TEXT
,
IN
__params
JSONB
,
IN
__id
JSONB
)
RETURNS
JSONB
LANGUAGE
'plpgsql'
IMMUTABLE
AS
$$
DECLARE
__api_type
TEXT
;
__method_type
TEXT
;
BEGIN
IF
__jsonrpc
!=
'2.0'
OR
__jsonrpc
IS
NULL
OR
__id
IS
NULL
OR
__method
IS
NULL
THEN
RAISE
EXCEPTION
'%'
,
hivemind_postgrest_utilities
.
raise_invalid_json_format_exception
(
'Invalid JSON-RPC'
);
END
IF
;
if
lower
(
__method
)
=
'call'
THEN
if
jsonb_array_length
(
__params
)
<
2
THEN
RAISE
EXCEPTION
'%'
,
hivemind_postgrest_utilities
.
raise_invalid_json_format_exception
(
'Invalid JSON-RPC'
);
END
IF
;
__api_type
=
__params
->>
0
;
__method_type
=
__params
->>
1
;
-- this 'call' keyword in test cases gives another error messages, so it is important
__params
=
jsonb_build_object
(
'used_call_keyword'
,
True
,
'params'
,
__params
->
2
);
ELSE
SELECT
split_part
(
__method
,
'.'
,
1
)
INTO
__api_type
;
SELECT
split_part
(
__method
,
'.'
,
2
)
INTO
__method_type
;
END
IF
;
RETURN
jsonb_build_object
(
'api_type'
,
__api_type
,
'method_type'
,
__method_type
,
'params'
,
__params
);
END
$$
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment