Skip to content

Commit

Permalink
make queries to use wallet indexes properly (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Aug 30, 2024
1 parent e3a423b commit ac4ff07
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-llamas-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'backend': patch
---

make queries to use wallet indexes properly
27 changes: 10 additions & 17 deletions modules/pool/lib/pool-gql-loader.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } };
Expand Down Expand Up @@ -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) => {
Expand All @@ -381,8 +381,7 @@ export class PoolGqlLoaderService {
some: {
token: {
address: {
equals: token,
mode: 'insensitive' as const,
equals: token.toLowerCase(),
},
},
},
Expand All @@ -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,
},
},
},
Expand All @@ -412,8 +410,7 @@ export class PoolGqlLoaderService {
userWalletBalances: {
some: {
userAddress: {
equals: userAddress,
mode: 'insensitive' as const,
equals: userAddress.toLowerCase(),
},
balanceNum: { gt: 0 },
},
Expand All @@ -423,8 +420,7 @@ export class PoolGqlLoaderService {
userStakedBalances: {
some: {
userAddress: {
equals: userAddress,
mode: 'insensitive' as const,
equals: userAddress.toLowerCase(),
},
balanceNum: { gt: 0 },
},
Expand Down Expand Up @@ -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()) } }
Expand Down Expand Up @@ -1324,8 +1319,7 @@ export class PoolGqlLoaderService {
userStakedBalances: {
where: {
userAddress: {
equals: userAddress,
mode: 'insensitive' as const,
equals: userAddress.toLowerCase(),
},
balanceNum: { gt: 0 },
},
Expand All @@ -1335,8 +1329,7 @@ export class PoolGqlLoaderService {
userWalletBalances: {
where: {
userAddress: {
equals: userAddress,
mode: 'insensitive' as const,
equals: userAddress.toLowerCase(),
},
balanceNum: { gt: 0 },
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- DropIndex
DROP INDEX "PrismaPoolDynamicData_totalShares_idx";

-- CreateIndex
CREATE INDEX "PrismaPoolDynamicData_totalSharesNum_idx" ON "PrismaPoolDynamicData"("totalSharesNum" DESC);
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion prisma/schema/pool.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ac4ff07

Please sign in to comment.