Skip to content

Commit 26a5915

Browse files
authored
perf: create index for tap receipts (#1202)
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
1 parent 693111f commit 26a5915

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Logger } from '@graphprotocol/common-ts'
2+
import { QueryInterface } from 'sequelize'
3+
4+
interface MigrationContext {
5+
queryInterface: QueryInterface
6+
logger: Logger
7+
}
8+
9+
interface Context {
10+
context: MigrationContext
11+
}
12+
13+
const INDEX_NAME = 'tap_horizon_receipts_collection_id'
14+
const INDEX_NAME_TEXT = 'tap_horizon_receipts_collection_text_id'
15+
16+
export async function up({ context }: Context): Promise<void> {
17+
const { queryInterface, logger } = context
18+
19+
logger.info(`Creating composite index ${INDEX_NAME} on tap_horizon_receipts`)
20+
await queryInterface.addIndex(
21+
'tap_horizon_receipts',
22+
['collection_id', 'id'],
23+
{
24+
name: INDEX_NAME,
25+
concurrently: true,
26+
},
27+
)
28+
logger.info(`Created index ${INDEX_NAME}`)
29+
30+
// This index can be removed if the indexer is running indexer-service v2.1.1
31+
// TODO: once there is sufficient indexer coverage remove it
32+
logger.info(
33+
`Creating composite index ${INDEX_NAME_TEXT} on tap_horizon_receipts`,
34+
)
35+
await queryInterface.sequelize.query(`
36+
CREATE INDEX CONCURRENTLY ${INDEX_NAME_TEXT}
37+
ON tap_horizon_receipts (CAST(collection_id AS TEXT), id)
38+
`)
39+
logger.info(`Created index ${INDEX_NAME_TEXT}`)
40+
}
41+
42+
export async function down({ context }: Context): Promise<void> {
43+
const { queryInterface, logger } = context
44+
45+
logger.info(`Dropping index ${INDEX_NAME}`)
46+
await queryInterface.removeIndex('tap_horizon_receipts', INDEX_NAME)
47+
48+
logger.info(`Dropping index ${INDEX_NAME_TEXT}`)
49+
await queryInterface.removeIndex('tap_horizon_receipts', INDEX_NAME_TEXT)
50+
}

0 commit comments

Comments
 (0)