From f20bc7c2a254b428fea71933102b85bc2047cf0b Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Wed, 11 Oct 2023 08:47:25 +0900 Subject: [PATCH 1/2] feat: allow filtering proposals by plugin and strategies --- src/graphql/operations/proposals.ts | 14 ++++++++++++-- src/graphql/schema.gql | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/graphql/operations/proposals.ts b/src/graphql/operations/proposals.ts index 71bacf95..f8c97840 100644 --- a/src/graphql/operations/proposals.ts +++ b/src/graphql/operations/proposals.ts @@ -55,9 +55,19 @@ export default async function (parent, args) { params.push(`%${where.plugins_contains}%`); } + if (where.strategies_in) { + searchSql += " AND JSON_OVERLAPS(JSON_EXTRACT(p.strategies, '$[*].name'), JSON_ARRAY(?))"; + params.push(where.strategies_in); + } + + if (where.plugins_in) { + searchSql += ' AND JSON_OVERLAPS(JSON_KEYS(p.plugins) , JSON_ARRAY(?))'; + params.push(where.plugins_in); + } + if (where.validation) { - searchSql += ' AND p.validation LIKE ?'; - params.push(`%"name": "${where.validation}"%`); + searchSql += " AND JSON_OVERLAPS(JSON_EXTRACT(p.validation, '$.name') , JSON_ARRAY(?))"; + params.push(where.validation); } if (where.space_verified) { diff --git a/src/graphql/schema.gql b/src/graphql/schema.gql index 73ee28c1..a5fbc4f6 100644 --- a/src/graphql/schema.gql +++ b/src/graphql/schema.gql @@ -177,6 +177,8 @@ input ProposalWhere { title_contains: String strategies_contains: String plugins_contains: String + strategies_in: [String] + plugins_in: [String] validation: String type: String type_in: [String] From 21c87a9f30341ea89174c810c6537cee7183ee2d Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:48:01 +0900 Subject: [PATCH 2/2] fix: improve query to make use of index --- src/graphql/operations/proposals.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphql/operations/proposals.ts b/src/graphql/operations/proposals.ts index f8c97840..5589feca 100644 --- a/src/graphql/operations/proposals.ts +++ b/src/graphql/operations/proposals.ts @@ -66,7 +66,7 @@ export default async function (parent, args) { } if (where.validation) { - searchSql += " AND JSON_OVERLAPS(JSON_EXTRACT(p.validation, '$.name') , JSON_ARRAY(?))"; + searchSql += " AND JSON_EXTRACT(p.validation, '$.name') = ?"; params.push(where.validation); }