Skip to content

Commit 085767b

Browse files
committed
fix: remove unused params and fix cache keys
1 parent ad1c82e commit 085767b

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

apps/indexer/src/app/plugins/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export type RouteCacheOptions = {
5454
*/
5555
backgroundRevalidate?: boolean;
5656
/** Build a custom cache key based on request */
57-
key?: (req: FastifyRequest) => string;
57+
key?: (req: FastifyRequest<any, any, any, any>) => string;
5858
};
5959

6060
export type RedisCachePluginOptions = {

apps/indexer/src/app/routes/_chain/routes.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import {
1616
fetchUserReserves,
1717
selectPoolById,
1818
} from '../../../libs/loaders/money-market';
19-
import { paginationResponse, paginationSchema } from '../../../libs/pagination';
19+
import {
20+
paginationResponse,
21+
paginationSchema,
22+
paginationSchemaQuery,
23+
} from '../../../libs/pagination';
2024
import { ZodFastifyInstance } from '../../../libs/server';
2125
import { ze } from '../../../libs/validators/validators';
2226

@@ -33,7 +37,8 @@ export default async function (fastify: ZodFastifyInstance) {
3337
},
3438
config: {
3539
cache: {
36-
key: (req) => `chain:${req.chain.chainId}:tokens`,
40+
key: (req) =>
41+
`chain:${req.chain.chainId}:tokens:${paginationSchemaQuery(req.query)}`,
3742
ttlSeconds: 30,
3843
enabled: true,
3944
},
@@ -58,7 +63,9 @@ export default async function (fastify: ZodFastifyInstance) {
5863
'/money-market',
5964
{
6065
config: {
61-
cache: true,
66+
cache: {
67+
key: (req) => `chain:${req.chain.chainId}:money-market:pools`,
68+
},
6269
},
6370
},
6471
async (req, reply) => {
@@ -81,13 +88,15 @@ export default async function (fastify: ZodFastifyInstance) {
8188
'/money-market/:pool/reserves',
8289
{
8390
schema: {
84-
querystring: paginationSchema,
8591
params: z.object({
8692
pool: z.string(),
8793
}),
8894
},
8995
config: {
90-
cache: false,
96+
cache: {
97+
key: (req: FastifyRequest<{ Params: { pool: string } }>) =>
98+
`chain:${req.chain.chainId}:money-market:reserves:${req.params.pool}`,
99+
},
91100
},
92101
},
93102
async (req: FastifyRequest<{ Params: { pool: string } }>, reply) => {
@@ -151,40 +160,28 @@ export default async function (fastify: ZodFastifyInstance) {
151160
isActive: item.isActive,
152161
isFroze: item.isFrozen,
153162
// eModes: item.eModes,
154-
i: item,
155163
};
156164
});
157165

158166
return { data: { reservesData: items, baseCurrencyData } };
159-
160-
// return {
161-
// data: items
162-
// .map((item) => ({
163-
// ...item,
164-
// token: tokens.find((t) => t.address === item.underlyingAsset),
165-
// }))
166-
// .filter((i) => i.token),
167-
// nextCursor: null,
168-
// count: items.length,
169-
// };
170167
},
171168
);
172169

173170
fastify.get(
174171
'/money-market/:pool/user/:address/positions',
175172
{
176173
schema: {
177-
querystring: paginationSchema,
178174
params: z.object({
179175
pool: z.string(),
180176
address: ze.address,
181177
}),
182178
},
183179
config: {
184180
cache: {
185-
enabled: false,
186-
ttlSeconds: 10,
187-
staleTtlSeconds: 15,
181+
key: (
182+
req: FastifyRequest<{ Params: { pool: string; address: string } }>,
183+
) =>
184+
`chain:${req.chain.chainId}:money-market:user-positions:${req.params.pool}:${req.params.address}`,
188185
},
189186
},
190187
},
@@ -442,7 +439,6 @@ export default async function (fastify: ZodFastifyInstance) {
442439
userEmodeCategoryId: summary.userEmodeCategoryId,
443440
isInIsolationMode: summary.isInIsolationMode,
444441
},
445-
reservesData,
446442
},
447443
};
448444
},

apps/indexer/src/libs/pagination.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ export const paginationResponse = <T>(
3939
count: items.length,
4040
};
4141
};
42+
43+
export const paginationSchemaQuery = (d: any) =>
44+
JSON.stringify({ limit: d.limit, cursor: d.cursor, search: d.search });

0 commit comments

Comments
 (0)