From ac4ff07898459da01b655c330fbedcb29227f704 Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:52:11 +0200 Subject: [PATCH] make queries to use wallet indexes properly (#872) --- .changeset/ten-llamas-flow.md | 5 ++++ modules/pool/lib/pool-gql-loader.service.ts | 27 +++++++------------ .../migration.sql | 5 ++++ prisma/schema.prisma | 2 +- prisma/schema/pool.prisma | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 .changeset/ten-llamas-flow.md create mode 100644 prisma/migrations/20240830154431_dynamic_data_index/migration.sql diff --git a/.changeset/ten-llamas-flow.md b/.changeset/ten-llamas-flow.md new file mode 100644 index 000000000..bc7dfd176 --- /dev/null +++ b/.changeset/ten-llamas-flow.md @@ -0,0 +1,5 @@ +--- +'backend': patch +--- + +make queries to use wallet indexes properly diff --git a/modules/pool/lib/pool-gql-loader.service.ts b/modules/pool/lib/pool-gql-loader.service.ts index 12c2bbc34..260f0ccb3 100644 --- a/modules/pool/lib/pool-gql-loader.service.ts +++ b/modules/pool/lib/pool-gql-loader.service.ts @@ -334,7 +334,7 @@ export class PoolGqlLoaderService { orderBy = { dynamicData: { totalLiquidity: orderDirection } }; break; case 'totalShares': - orderBy = { dynamicData: { totalShares: orderDirection } }; + orderBy = { dynamicData: { totalSharesNum: orderDirection } }; break; case 'volume24h': orderBy = { dynamicData: { volume24h: orderDirection } }; @@ -372,7 +372,7 @@ export class PoolGqlLoaderService { } const where = args.where; - const textSearch = args.textSearch ? { contains: args.textSearch, mode: 'insensitive' as const } : undefined; + const textSearch = args.textSearch ? { contains: args.textSearch.toLowerCase() } : undefined; const allTokensFilter = []; where?.tokensIn?.forEach((token) => { @@ -381,8 +381,7 @@ export class PoolGqlLoaderService { some: { token: { address: { - equals: token, - mode: 'insensitive' as const, + equals: token.toLowerCase(), }, }, }, @@ -396,8 +395,7 @@ export class PoolGqlLoaderService { every: { token: { address: { - notIn: where.tokensNotIn || undefined, - mode: 'insensitive' as const, + notIn: where.tokensNotIn.map((t) => t.toLowerCase()) || undefined, }, }, }, @@ -412,8 +410,7 @@ export class PoolGqlLoaderService { userWalletBalances: { some: { userAddress: { - equals: userAddress, - mode: 'insensitive' as const, + equals: userAddress.toLowerCase(), }, balanceNum: { gt: 0 }, }, @@ -423,8 +420,7 @@ export class PoolGqlLoaderService { userStakedBalances: { some: { userAddress: { - equals: userAddress, - mode: 'insensitive' as const, + equals: userAddress.toLowerCase(), }, balanceNum: { gt: 0 }, }, @@ -460,9 +456,8 @@ export class PoolGqlLoaderService { }, AND: allTokensFilter, id: { - in: where?.idIn || undefined, - notIn: where?.idNotIn || undefined, - mode: 'insensitive', + in: where?.idIn?.map((id) => id.toLowerCase()) || undefined, + notIn: where?.idNotIn?.map((id) => id.toLowerCase()) || undefined, }, ...(where?.categoryIn && !where?.tagIn ? { categories: { hasSome: where.categoryIn.map((s) => s.toUpperCase()) } } @@ -1324,8 +1319,7 @@ export class PoolGqlLoaderService { userStakedBalances: { where: { userAddress: { - equals: userAddress, - mode: 'insensitive' as const, + equals: userAddress.toLowerCase(), }, balanceNum: { gt: 0 }, }, @@ -1335,8 +1329,7 @@ export class PoolGqlLoaderService { userWalletBalances: { where: { userAddress: { - equals: userAddress, - mode: 'insensitive' as const, + equals: userAddress.toLowerCase(), }, balanceNum: { gt: 0 }, }, diff --git a/prisma/migrations/20240830154431_dynamic_data_index/migration.sql b/prisma/migrations/20240830154431_dynamic_data_index/migration.sql new file mode 100644 index 000000000..c387cf206 --- /dev/null +++ b/prisma/migrations/20240830154431_dynamic_data_index/migration.sql @@ -0,0 +1,5 @@ +-- DropIndex +DROP INDEX "PrismaPoolDynamicData_totalShares_idx"; + +-- CreateIndex +CREATE INDEX "PrismaPoolDynamicData_totalSharesNum_idx" ON "PrismaPoolDynamicData"("totalSharesNum" DESC); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9224bee17..40701e409 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -141,7 +141,7 @@ model PrismaPoolDynamicData { @@unique([poolId, chain]) // Indexes used for sorting pools in the UI by different metrics @@index(totalLiquidity) - @@index(totalShares) + @@index(totalSharesNum(sort: Desc)) @@index(volume24h) @@index(apr) diff --git a/prisma/schema/pool.prisma b/prisma/schema/pool.prisma index 669a3b1fb..43c756971 100644 --- a/prisma/schema/pool.prisma +++ b/prisma/schema/pool.prisma @@ -67,7 +67,7 @@ model PrismaPoolDynamicData { @@unique([poolId, chain]) // Indexes used for sorting pools in the UI by different metrics @@index(totalLiquidity) - @@index(totalShares) + @@index(totalSharesNum(sort: Desc)) @@index(volume24h) @@index(apr)