Skip to content

Commit 1cab901

Browse files
committed
refactor: improved the lastTokenPriceInKda query
1 parent 593fe4e commit 1cab901

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
/** @type {import('sequelize-cli').Migration} */
4+
module.exports = {
5+
async up(queryInterface) {
6+
await queryInterface.sequelize.query(`
7+
DROP INDEX IF EXISTS transactions_result_gin_idx;
8+
`);
9+
},
10+
11+
async down(queryInterface) {
12+
await queryInterface.sequelize.query(`
13+
CREATE INDEX IF NOT EXISTS transactions_result_gin_idx ON "Transactions" USING gin (result);
14+
`);
15+
},
16+
};

indexer/src/kadena-server/resolvers/query/last-token-price-in-kda-resolver.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ export const lastTokenPriceInKdaQueryResolver: QueryResolvers<ResolverContext>['
88
const query = `
99
SELECT t.result
1010
FROM public."Transactions" t
11-
WHERE t.result::text LIKE '%' || $1 || '%'
12-
ORDER BY t.creationtime DESC, t.id DESC
11+
JOIN public."TransactionDetails" td ON td."transactionId" = t.id
12+
WHERE td.code LIKE '%[' || $1 || ' coin]%'
13+
AND t.result::text LIKE '%' || '"token": "' || $1 || '"' || '%'
14+
AND t.result::text LIKE '%' || '"status": "success"' || '%'
15+
ORDER BY td.id DESC
1316
LIMIT 1
1417
`;
1518

0 commit comments

Comments
 (0)