Skip to content

Commit

Permalink
api: fix proof/root query to be more specific (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
worm-emoji authored Sep 1, 2022
1 parent 52ff3a8 commit d16ac8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions api/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,23 @@ var Migrations = []migrate.Migration{
SET NOT NULL;
`,
},
{
Name: "2022-08-31.0.root-func-index.sql",
SQL: `
CREATE OR REPLACE FUNCTION proofs_array (data jsonb)
RETURNS text[]
AS $CODE$
BEGIN
RETURN ARRAY (
SELECT
jsonb_array_elements(data) ->> 'proof');
END
$CODE$
LANGUAGE plpgsql
IMMUTABLE;
CREATE INDEX proofs_arr_idx ON trees USING GIN ((proofs_array(proofs)));
DROP INDEX "trees_proofs_idx";
`,
},
}
2 changes: 1 addition & 1 deletion api/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *Server) GetRoot(w http.ResponseWriter, r *http.Request) {
const q = `
SELECT root
FROM trees
WHERE proofs @> $1
WHERE proofs_array(proofs) @> proofs_array($1)
LIMIT 1
`

Expand Down

1 comment on commit d16ac8c

@vercel
Copy link

@vercel vercel bot commented on d16ac8c Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lanyard – ./

lanyard-git-main.context.wtf
allowlist.context.wtf
lanyard.context.wtf

Please sign in to comment.