Skip to content

Commit e1044d1

Browse files
authored
fix: optimize contract event list db index (#2258)
1 parent e62ce79 commit e1044d1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable camelcase */
2+
3+
exports.shorthands = undefined;
4+
5+
exports.up = pgm => {
6+
pgm.dropIndex('contract_logs', 'contract_identifier');
7+
pgm.dropIndex('contract_logs', [
8+
{ name: 'block_height', sort: 'DESC' },
9+
{ name: 'microblock_sequence', sort: 'DESC' },
10+
{ name: 'tx_index', sort: 'DESC' },
11+
{ name: 'event_index', sort: 'DESC' },
12+
]);
13+
14+
pgm.createIndex(
15+
'contract_logs',
16+
[
17+
'contract_identifier',
18+
{ name: 'block_height', sort: 'DESC' },
19+
{ name: 'microblock_sequence', sort: 'DESC' },
20+
{ name: 'tx_index', sort: 'DESC' },
21+
{ name: 'event_index', sort: 'DESC' },
22+
],
23+
{ where: 'canonical = TRUE AND microblock_canonical = TRUE' }
24+
);
25+
};
26+
27+
exports.down = pgm => {
28+
pgm.dropIndex(
29+
'contract_logs',
30+
[
31+
'contract_identifier',
32+
{ name: 'block_height', sort: 'DESC' },
33+
{ name: 'microblock_sequence', sort: 'DESC' },
34+
{ name: 'tx_index', sort: 'DESC' },
35+
{ name: 'event_index', sort: 'DESC' },
36+
],
37+
{ where: 'canonical = TRUE AND microblock_canonical = TRUE' }
38+
);
39+
40+
pgm.createIndex('contract_logs', 'contract_identifier');
41+
pgm.createIndex('contract_logs', [
42+
{ name: 'block_height', sort: 'DESC' },
43+
{ name: 'microblock_sequence', sort: 'DESC' },
44+
{ name: 'tx_index', sort: 'DESC' },
45+
{ name: 'event_index', sort: 'DESC' },
46+
]);
47+
};

0 commit comments

Comments
 (0)